Submission
Status:
PPPPP--P-P
Subtask/Task Score:
70/100
Score: 70
User: devilpoohs
Problemset: Fool's Compensation
Language: cpp
Time: 0.003 second
Submitted On: 2026-03-08 12:52:30
#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(ii-1>=0 and ara[ii]!=ara[ii-1])
ar[ii]=max(ar[ii],ar[ii-1]+1);
if(ii+1<n and ara[ii]!=ara[ii+1])
ar[ii]=max(ar[ii],ar[ii+1]+1);
if(st.empty()){
st.emplace(ii);
temp=ar[ii];
}else{
if(ara[ii]==ara[st.top()]){
st.emplace(ii);
temp=max(temp,ar[ii]);
}else if(ara[ii]!=ara[st.top()]){
while(!st.empty()){
// cout<<st.top()<<' ';
ar[st.top()]=temp;
st.pop();
}
// cout<<'\n';
temp=ar[ii];
st.emplace(ii);
}
if(i==n-1){
while(!st.empty()){
// cout<<st.top()<<' ';
ar[st.top()]=temp;
st.pop();
}
}
// cout<<i<<',';
// for(int j=0;j<n;j++){
// cout<<ar[j]<<' ';
// }
// cout<<'\n';
}
// if(i>=0 and pa[i].f==pa[i-1].f){
// temp=0;
// temp=max(temp,ar[pa[i].s]);
// temp=max(temp,ar[pa[i-1].s]);
// ar[pa[i].s]=temp;
// ar[pa[i-1].s]=temp;
// }
}
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
*/