大佬求助样例过了,思路也对,但是全RE,能帮忙优化一下吗,谢谢

P5788 【模板】单调栈

a,ans 数组开太大了?
by Night_fall @ 2023-05-20 10:45:38


@[Nightfall__Minecraft](/user/688674) 3e6+5 也RE
by pyq2021 @ 2023-05-20 10:59:07


ai<=1e9
by c21162wqb @ 2023-05-20 11:44:28


@[c21162wqb](/user/614509) 开1e9会爆
by pyq2021 @ 2023-05-22 16:21:27


@[pyq2021](/user/657485) 我用的快速读入,你可以按照我的试一下 ```cpp #include<iostream> #include<stack> using namespace std; stack<int> s; int n,a[3000001],ans[3000001]; inline int read() { int x=0,f=1; char ch=getchar(); while(!isdigit(ch)) { if(ch=='-') f=-1; ch=getchar(); } while(isdigit(ch)) { x=x*10+ch-'0'; ch=getchar(); } return x*f; } int main() { cin>>n; for(int i=1;i<=n;i++) a[i]=read(); for(int i=n;i>=1;i--) { while(!s.empty()&&a[i]>=a[s.top()]) s.pop(); if(s.empty()) ans[i]=0; else ans[i]=s.top(); s.push(i); } for(int i=1;i<=n;i++) cout<<ans[i]<<' '; return 0; } ``` 我们应该中间写的差不多,求关QWQ
by Li_wc @ 2023-08-16 14:48:46


|