BOJ 2493: 탑

https://www.acmicpc.net/problem/2493

  • 2월동안 187문제 풀기(지난달 누적 87개) (59/187)
  • 아주 전형적인 스택문제. 이전 top 보다 작은거는 고려대상이 아님
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <bits/stdc++.h>
using namespace std;

//FIO
fio io;

int N, x, INF=2e9;
vector<pair<int,int>> st;

int main() {
  N = io.readInt();
  st.push_back({INF, 0});
  for(int i = 1; i <= N; i++) {
    x = io.readInt();
    while (st.back().first < x) st.pop_back();
    cout << st.back().second << ' ';
    st.push_back({x,i});
  }
}