0分求助

P5788 【模板】单调栈

```cpp #include <bits/stdc++.h> int n,x; using namespace std; int a[3000001],s[3000001],id[3000001],top; int main(){ scanf("%d",&n); for(int i=1;i<=n;++i){ scanf("%d",&a[i]); } for(int i=n;i>=1;i--){ while(top && a[s[top]]<=a[i]) top--; if(!top) id[i]=0; else id[i]=s[top]; s[++top]=i; } for(int i=1;i<=n;i++) printf("%d ",id[i]); } ``` 1. a 数组小了 2. 有一个地方你写错了自己看一下
by Meteor_ @ 2023-09-24 16:08:55


@[blackmonkey](/user/636008)
by Meteor_ @ 2023-09-24 16:09:13


@[Meteor_](/user/756594) 以关,但没看出来哪写错了,还请大佬指点
by blackmonkey @ 2023-09-24 16:50:03


你看看你while里面写了点什么 算了再提示一点吧:($a[s[top]<=a[i]]$ 这是你写的)
by Meteor_ @ 2023-09-24 16:51:47


@[blackmonkey](/user/636008)
by Meteor_ @ 2023-09-24 16:52:08


@[blackmonkey](/user/636008) ?懂了吗
by Meteor_ @ 2023-09-24 17:24:27


@[Meteor_](/user/756594) 懂了懂了谢谢
by blackmonkey @ 2023-09-25 18:58:08


|