Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
142290 | baim. | 音乐会 | C++ | 通过 | 100 | 44 MS | 12216 KB | 1474 | 2024-04-06 21:31:59 |
#include<bits/stdc++.h> using namespace std; typedef long long LL; struct asd{ int w; LL Left; //就是表它向右的答案 LL cet; //右边重复个数 }; int n,x; stack<asd>q; LL ans; int main() { while(!q.empty()) q.pop(); scanf("%d",&n); asd now,nex; ans=0; for(int i=1;i<=n;i++) { scanf("%d",&x); now.Left=0; //都有它一个。 now.cet=0; now.w=x; if(q.empty()) q.push(now); else { if(q.top().w>=now.w) q.push(now); else { while(!q.empty()&&q.top().w<now.w) { nex=q.top();q.pop(); ans=ans+nex.Left+1LL; //直接+答案咯 if(!q.empty()) { q.top().Left+=nex.cet+1LL; if(q.top().w==nex.w) q.top().cet+=nex.cet+1LL; } //printf("%d %lld\n",x,ans); } q.push(now); } } } while(!q.empty()) { nex=q.top();q.pop(); if(!q.empty()) { q.top().Left+=nex.cet+1LL; if(q.top().w==nex.w) q.top().cet+=nex.cet+1LL; } ans=ans+nex.Left; } printf("%lld\n",ans); return 0; }