社区讨论
30分求助
P2866[USACO06NOV] Bad Hair Day S参与者 2已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @m3cxq6d9
- 此快照首次捕获于
- 2024/11/11 19:23 去年
- 此快照最后确认于
- 2025/11/04 14:54 4 个月前
CPP
#include<bits/stdc++.h>
using namespace std;
long long n,a[1010000],st[1010000],top,s[1010000],cnt;
int main(){
scanf("%lld",&n);
for(int i=1;i<=n;i++){
scanf("%lld",&a[i]);
while(top>0&&a[st[top]]<a[i]){
s[st[top]]=i;
st[top]=0;
top--;
}
st[++top]=i;
}
for(int i=1;i<=n;i++){
if(s[i]!=0)
cnt+=(s[i]-i-1);
else{
if(i!=n){
cnt+=n-i;
}
}
}
printf("%lld",cnt);
return 0;
}
回复
共 2 条回复,欢迎继续交流。
正在加载回复...