Submission
Status:
PPPPP--P-P
Subtask/Task Score:
70/100
Score: 70
User: devilpoohs
Problemset: Fool's Compensation
Language: cpp
Time: 0.004 second
Submitted On: 2026-03-08 13:36:24
#include<bits/stdc++.h>
using namespace std;
#define f first
#define s second
bool comp(pair<int,int>& a,pair<int,int>& b){
return a.s<b.s;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin>>n;
pair<int,int> pa[n];
int ar[n];
int ara[n];
for(int i=0;i<n;i++){
cin>>pa[i].f;
pa[i].s=i;
ar[i]=0;
ara[i]=pa[i].f;
}
sort(pa,pa+n);
int temp;
stack<int> st;
for(int i=0;i<n;i++){
int ii=pa[i].s;
if(st.empty()){
st.emplace(ii);
temp=max(ar[max(ii-1,0)]+1,ar[min(n-1,ii+1)]+1);
}else{
if(ara[ii]==ara[st.top()]){
st.emplace(ii);
temp=max(temp,ar[ii]);
}else{
while(!st.empty()){
ar[st.top()]=temp;
st.pop();
}
temp=max(ar[max(ii-1,0)]+1,ar[min(n-1,ii+1)]+1);
st.emplace(ii);
}
if(i==n-1){
while(!st.empty()){
ar[st.top()]=temp;
st.pop();
}
}
}
// cout<<i<<',';
// for(int j=0;j<n;j++){
// cout<<ar[j]<<' ';
// }
// cout<<'\n';
}
sort(pa,pa+n,comp);
int sum=0;
for(int i=0;i<n;i++){
// cout<<ar[i]<<',';
sum+=ar[i];
}
cout<<sum<<"000";
return 0;
}
/*
7
3
1
2
3
3
2
1
8
7 4 5 1 7 1 2 7
*/