小蒟蒻再次求教

P5788 【模板】单调栈

emmmmmm
by pidan @ 2020-02-20 21:22:14


我给您贴代码好吗
by pidan @ 2020-02-20 21:22:35


@[文·和](/user/127520) ```cpp #include<bits/stdc++.h> #define int long long using namespace std; int read(){ int w=0,h=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')h=-1;ch=getchar();} while(ch>='0'&&ch<='9'){w=w*10+ch-'0';ch=getchar();} return w*h; } int n,a[3000010],Stack[3000010],top,ans[3000010]; signed main(){ n=read();for(int i=1;i<=n;i++)a[i]=read(); for(int i=n;i>=1;i--){ while(top&&a[Stack[top]]<=a[i])top--; ans[i]=Stack[top]; Stack[++top]=i; } for(int i=1;i<=n;i++)cout<<ans[i]<<" "; return 0; } ```
by pidan @ 2020-02-20 21:23:34


快读多好……
by pidan @ 2020-02-20 21:24:13


~~看来您这个奆佬遇到了一些小问题鸭~~QAQ
by pidan @ 2020-02-20 21:25:39


@[pidan](/user/191538) 然而还是不行 ``` #include <bits/stdc++.h> using namespace std; long long read(){ long long w=0,h=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')h=-1;ch=getchar();} while(ch>='0'&&ch<='9'){w=w*10+ch-'0';ch=getchar();} return w*h; } long long n,k,s[3000006],ans[3000006],q[3000006]; signed main(){ n=read(); for(long long i=1;i<=n;i++) s[i]=read(); for(long long i=n;i>=1;i--){ while(k>0&&s[q[k]]<s[i]) k--; ans[i]=q[k]; k++; q[k]=i; } for(long long i=1;i<=n;i++) printf("%d ",ans[i]); return 0; } ```
by 文·和 @ 2020-02-21 09:12:41


已经改成lld了
by 文·和 @ 2020-02-21 09:18:24


emmmmm
by pidan @ 2020-02-21 09:27:23


我测了一下,你的代码是错的,把while里面的《 <改成<=
by pidan @ 2020-02-21 09:30:36


@[文·和](/user/127520)
by pidan @ 2020-02-21 09:30:52


| 下一页