提交时间:2024-08-21 16:49:17

运行 ID: 180638

#include <iostream> #define N 500003 using namespace std; long long same[N],q[N]; long long n,t,ans,a[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; }