Created
January 26, 2020 09:02
-
-
Save inspirit941/d76d6b8c95eb72beed7c549f4286878b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
sys.stdin = open('input.txt') | |
n = int(sys.stdin.readline()) | |
arr = list(map(int, sys.stdin.readline().split())) | |
answer = [0 for _ in range(len(arr))] | |
stack = [] | |
for i in range(len(arr)-1, -1, -1): | |
while stack and arr[stack[-1]] < arr[i]: | |
answer[stack.pop()] = i+1 | |
stack.append(i) | |
print(*answer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment