提交时间:2024-08-21 16:12:44
运行 ID: 180575
#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() { cin>>n; for(int i=1;i<=n;++i) { cin>>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; } cout<<ans; return 0; }