Submission #2861985


Source Code Expand

#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
using namespace std;
int mod = 1e9+7;

int main() {
  int n;
  cin >> n;
  vector<long long int> a(n+1);
  for(int i=0; i<n; i++){
    long long int tmp;
    cin >> tmp;
    a[tmp] = i;
  }

  long long int ans = 0;
  set<long long int> s;
  s.insert(-1);
  s.insert(n);
  for(int i=1; i<=n; i++){
    long long int p = a[i];
    auto it = s.lower_bound(p);
    long long int r = *it;
    it--;
    long long int l = *it;
    ans += i * (p-l) * (r-p);
    s.insert(p);
  }

  cout << ans << endl;

  return 0;
}

//

Submission Info

Submission Time
Task B - Minimum Sum
User yut071
Language C++14 (GCC 5.4.1)
Score 400
Code Size 798 Byte
Status AC
Exec Time 160 ms
Memory 11136 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 13
Set Name Test Cases
Sample example0, example1, example2
All corner0, corner1, corner2, corner3, example0, example1, example2, maxrand0, maxrand1, maxrand2, rand0, rand1, rand2
Case Name Status Exec Time Memory
corner0 AC 158 ms 11136 KB
corner1 AC 160 ms 11136 KB
corner2 AC 1 ms 256 KB
corner3 AC 111 ms 11136 KB
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
maxrand0 AC 150 ms 11136 KB
maxrand1 AC 146 ms 11136 KB
maxrand2 AC 146 ms 11136 KB
rand0 AC 1 ms 256 KB
rand1 AC 1 ms 256 KB
rand2 AC 1 ms 256 KB