警示及提示

P5788 【模板】单调栈

@[hhc2012](/user/928986) 不是,用单调栈呀! ```cpp #include<cstdio> #include<stack> using namespace std; int n,a[3000005],f[3000005]; stack<int>s; int main() { scanf("%d",&n); for(int i=1;i<=n;i++) scanf("%d",&a[i]); for(int i=n;i>=1;i--) { while(!s.empty()&&a[s.top()]<=a[i]) s.pop(); f[i]=s.empty()?0:s.top(); s.push(i); } for(int i=1;i<=n;i++) printf("%d ",f[i]); return 0; } ```
by sherry_lover @ 2023-05-05 17:39:41


@[lzr121107](/user/686281) upd(20230510): # upd for 提示板块 3. 数组可能会爆,建议按数据行事
by hhce2012 @ 2023-05-10 16:47:18


@[hhc2012](/user/928986) [AC记录](https://www.luogu.com.cn/record/109987356)
by sherry_lover @ 2023-05-10 17:29:03


@[lzr121107](/user/686281) 我的意思是在其他题目上。
by hhce2012 @ 2023-05-11 20:17:16


@[lzr121107](/user/686281) 而且,不写等于号更保险。
by hhce2012 @ 2023-05-11 20:17:59


|