728x90
#include <iostream>
#include <vector>
#include <memory.h>
using namespace std;
const int MAX = 500001;
int n;
int tower[MAX];
vector<int> stack;
void init(){
memset(tower, 0, sizeof(tower));
}
void input(){
cin >> n;
for(int i = 0; i < n; i++){
cin >> tower[i];
}
}
void print(){
if(stack.empty()) cout << 0 << " ";
else{
cout << stack.back() + 1 << " ";
}
}
void sol(){
for(int i = 0; i < n; i++){
int tmp = tower[i];
if(stack.empty()) {
stack.push_back(i);
cout << 0 << " ";
}
else{
while(!stack.empty()){
if(tower[stack.back()] > tmp) {
print();
break;
}
else{
stack.pop_back();
}
}
if(stack.empty())cout << 0 << " ";
stack.push_back(i);
}
}
}
int main(){
input();
sol();
return 0;
}
728x90
'알고리즘 문제 > 자료구조' 카테고리의 다른 글
[개쉬운 풀이] 백준 22866 탑 보기 CPP (18일차) (0) | 2024.12.09 |
---|---|
[개쉬운 풀이] 백준 1725 히스토그램 CPP (15일차) (0) | 2024.12.06 |
[개쉬운 풀이] 백준 1863 스카이라인 쉬운거 (0) | 2024.09.16 |