[문제]
https://www.acmicpc.net/problem/2493
[풀이]
스택
[코드]
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
stack <pair<int, int>> S;
vector <int> V;
int cnt = 1;
while(n--){
int t;
cin >> t;
if(S.empty()) {
V.push_back(0);
}
else {
if(S.top().first >= t) {
V.push_back(S.top().second);
}
else {
while(!S.empty()) {
if(S.top().first >= t){
V.push_back(S.top().second);
break;
}
S.pop();
}
if(S.empty()) V.push_back(0);
}
}
S.push({t, cnt++});
}
for(int i=0; i<V.size(); i++){
cout << V[i] << " ";
}
}