提交时间:2024-08-21 17:20:33

运行 ID: 180691

#include<bits/stdc++.h> using namespace std; const int N=5e5+10; long long a[N],n,ans; long long same[N],t,q[N]; int main() { scanf("%lld",&n); for(int i=1;i<=n;++i) { scanf("%lld",&a[i]); } for(int i=1;i<=n;++i) { while(t!=0 && a[q[t]]<=a[i]) { if(a[q[t]]==a[i])same[i]=same[q[t]]+1; ans+=same[q[t]]+1; q[t--]=0; } if(t!=0)ans++; q[++t]=i; } printf("%lld\n",ans); return 0; }