Submission #1589639


Source Code Expand

#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<deque>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<time.h>
#include<cstdlib>
#include<cassert>
#define ll long long
#define fi first
#define se second
using namespace std;
void aho(string s,ll a){
  cout<<s<<"="<<a<<endl;
  return;
}

int n;
int a[200001];
int b[200001];
                   
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>a[i];
    b[a[i]]=i+1;
  }
  set<int> s;
  s.insert(0);
  s.insert(n+1);
  ll res=0;
  for(int i=1;i<=n;i++){
    int index=b[i];
    auto ite=s.lower_bound(index);
    ll left=(*ite)-index;
    ite--;
    ll right=index-(*ite);
    res+=i*left*right;
    s.insert(index);
    //aho("left",left);
    //aho("right",right);
    //cout<<res<<endl;
  }
  cout<<res<<"\n";
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

Submission Info

Submission Time
Task B - Minimum Sum
User aim_cpo
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1303 Byte
Status AC
Exec Time 132 ms
Memory 11264 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 122 ms 11264 KB
corner1 AC 125 ms 11136 KB
corner2 AC 1 ms 256 KB
corner3 AC 74 ms 11136 KB
example0 AC 1 ms 256 KB
example1 AC 1 ms 256 KB
example2 AC 1 ms 256 KB
maxrand0 AC 120 ms 11136 KB
maxrand1 AC 132 ms 11264 KB
maxrand2 AC 124 ms 11264 KB
rand0 AC 1 ms 256 KB
rand1 AC 1 ms 256 KB
rand2 AC 1 ms 256 KB