https://www.acmicpc.net/problem/2493
import sys
input = sys.stdin.readline
num = int(input())
tower = list(map(int, input().split()))
stack = []
ans = []
for i in range(num):
while stack:
if stack[-1][1] > tower[i]:
ans.append(stack[-1][0]+1)
break
else:
stack.pop()
if not stack:
ans.append(0)
stack.append([i, tower[i]])
print(*ans, end="")
백준 17298과 풀이가 유사하다.