求调wa on #7~#10单调栈思路

P5788 【模板】单调栈

```cpp #include<bits/stdc++.h> using namespace std; int n,c[3000005]; struct u{ int xx; int yy; }; u a[3000005]; stack<u > p; int main(){ cin>>n; for(int i=1;i<=n;i++){ cin>>a[i].xx; a[i].yy=i; } for(int i=n;i>=1;i--){ //倒着来 while(!p.empty()&&p.top().xx<=a[i].xx){ p.pop(); } c[i]=p.empty()?0:p.top().yy;//外面统计 p.push(a[i]); } for(int i=1;i<=n;i++) cout<<c[i]<<' '; return 0; } ``` 给个关吧谢谢
by z_z_b_ @ 2024-05-07 21:08:03


@[zombiell810975](/user/1104479)
by z_z_b_ @ 2024-05-07 21:08:15


@[zombiell810975](/user/1104479) 从n到1枚举
by run_away @ 2024-05-07 21:10:39


@[z_z_b_](/user/956129) 感谢已回
by zombiell810975 @ 2024-05-08 17:45:40


|