- sol1: deque(stack + queue) 풀이
- 스택에 임시 값을 넣는다.
- 현재 높이보다 더 큰 값을 스택에서 발견할 때까지 pop()을 수행한다.
- 수행 후, 스택의 top()엔 레이저 신호를 수신할 수 있는 pair 값이 남아있을 것
- 해당 pair에서 원하는 값을 출력하고, 현재 값을 stack에 push()한다.
#include <bits/stdc++.h> using namespace std; int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int count; stack<int> s; long long height, ans = 0; cin >> count; while(count--){ cin >> height; //2. i) 스택에 있는 건물 중, 현재 건물보다 작은 건물들을 모두 빼줌 while(!s.empty() && s.top() <= height) s.pop(); //2. ii) 건물을 다 빼줬으면, 스택에 있는 개수만큼 값에 더해줍니다. ans += s.size(); //2. iii) 해당 입력을 스택에 넣어줍니다. s.push(height); } cout << ans; }