题目描述
单调栈
这题Y总讲的太透彻了!!!
C++代码
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int stk[N], t = 0;
int main(){
int n, x;
cin >> n;
while(n--){
cin >> x;
while(t && stk[t] >= x)
t--;
if(t)
cout << stk[t] << " ";
else
cout << "-1 ";
stk[++t] = x;
}
return 0;
}