#include <bits/stdc++.h>
using namespace std;
int n;
long long st[100010], top, ans, h;
int main(){
//freopen("input.txt", "r", stdin);
scanf("%d", &n);
st[0] = 1e9 + 10, top = ans = 0;
for(int i = 1; i <= n; i++){
scanf("%lld", &h);
while(st[top] <= h) top--;
ans += top;
st[++top] = h;
}
cout << ans << endl;
return 0;
}
单调栈 - 洛谷 P2866
最新推荐文章于 2025-11-23 09:55:04 发布
这篇博客介绍了一种高效算法,用于在一个动态更新的区间中找到最高堆顶元素的应用。通过C++代码实现,探讨了如何维护堆数据结构并更新答案,适用于实时数据流处理场景。
485

被折叠的 条评论
为什么被折叠?



