Written by
최태열
on
on
[c++][정올][Intermediate_Coder] 1328 : 빌딩
[c++][정올][Intermediate_Coder] 1328 : 빌딩
코드
#include <iostream>
#include <vector>
#include <deque>
using namespace std;
int main() {
int N;
cin>>N;
vector<int> buildings(N);
for (int i=0; i<N; i++){
cin>>buildings[i];
}
vector<int> answer(N);
deque<int> dq;
for (int i=0; i<N; i++){
while (!dq.empty() and buildings[dq.back()]<buildings[i]){
int ck = dq.back();
dq.pop_back();
answer[ck] = i+1;
}
dq.push_back(i);
}
for (int ans : answer){
cout<<ans<<"\n";
}
}
Discussion and feedback