Submission #4034592


Source Code Expand

#include<iostream>
using namespace std;
typedef long long ll;
#define fr(i,n) for(int i=0;i<n;i++)

int main(){
  ll n,a[200010],b[200010],L[200010],R[200010],c=0,j,l,r,k;
  cin>>n;
  fr(i,n){
    cin>>a[i];
    b[a[i]]=i+1;
  }
  fr(i,n+2){
    L[i]=i;
    R[i]=i;
  }
  fr(i,n){
    j=n-i;
    k=b[j];
    l=L[k];
    r=R[k];
    c+=j*(k-l+1)*(r-k+1);
    L[r+1]=l;
    R[l-1]=r;
  }
  cout<<c<<endl;
}

Submission Info

Submission Time
Task B - Minimum Sum
User Motsu_xe
Language C++14 (GCC 5.4.1)
Score 400
Code Size 430 Byte
Status AC
Exec Time 64 ms
Memory 6528 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 61 ms 6528 KB
corner1 AC 61 ms 6528 KB
corner2 AC 2 ms 4352 KB
corner3 AC 61 ms 6528 KB
example0 AC 2 ms 4352 KB
example1 AC 2 ms 4352 KB
example2 AC 2 ms 4352 KB
maxrand0 AC 62 ms 6528 KB
maxrand1 AC 62 ms 6528 KB
maxrand2 AC 64 ms 6528 KB
rand0 AC 2 ms 4352 KB
rand1 AC 2 ms 4352 KB
rand2 AC 2 ms 4352 KB