1 solutions
-
1
#include<bits/stdc++.h> using namespace std; const int N=1e5+10; int stk[N],tt; //单调栈结构 int main() { int n; cin>>n; for(int i=1;i<=n;i++) { int x; cin>>x; while(tt&&stk[tt]>=x) tt--; //栈中元素大于等于当前元素(一定不可能是答案) if(tt) cout<<stk[tt]<<" "; //如果栈中还有元素,一定比当前元素小 else cout<<"-1 "; //输出无解 stk[++tt]=x; //记录当前元素 } return 0; }
Information
- ID
- 334
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 5
- Tags
- # Submissions
- 9
- Accepted
- 7
- Uploaded By