PS/자료 구조
[백준] No.2493 탑 完
_빌런
2023. 8. 23. 10:44
# ---------- Import ----------
import sys
input = sys.stdin.readline
# ---------- Main ----------
_ = int(input())
buildings = list(map(int, input().split()))
stack = []
for idx, now in enumerate(buildings):
while stack and stack[-1][0] < now:
stack.pop()
if stack:
print(stack[-1][1], end=" ")
else:
print(0, end=" ")
stack.append((now, idx + 1))