Submission #1623864


Source Code Expand

Copy
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;
int main(){
  int N;
  cin >> N;
  int A[N], id[N+1];
  for(int i = 0; i < N; ++i){
    cin >> A[i];
    id[A[i]] = i;
  }
  long long int ans = 0LL;
  set<int> S;
  S.insert(N);
  S.insert(-1);
  for(int i = 1; i <= N; ++i){
    S.insert(id[i]);
    set<int>::iterator itr = S.find(id[i]), l = itr, r = itr;
    --l;
    ++r;
    ans += (long long int)(id[i] - *l)*(*r - id[i])*i;
  }
  cout << ans << endl;
  return 0;
}

Submission Info

Submission Time
Task B - Minimum Sum
User TAB
Language C++14 (GCC 5.4.1)
Score 400
Code Size 526 Byte
Status
Exec Time 165 ms
Memory 11136 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 example0, example1, example2
All 400 / 400 corner0, corner1, corner2, corner3, example0, example1, example2, maxrand0, maxrand1, maxrand2, rand0, rand1, rand2
Case Name Status Exec Time Memory
corner0 164 ms 11136 KB
corner1 163 ms 11136 KB
corner2 1 ms 256 KB
corner3 114 ms 11136 KB
example0 1 ms 256 KB
example1 1 ms 256 KB
example2 1 ms 256 KB
maxrand0 154 ms 11136 KB
maxrand1 157 ms 11136 KB
maxrand2 165 ms 11136 KB
rand0 1 ms 256 KB
rand1 1 ms 256 KB
rand2 1 ms 256 KB