Created
May 3, 2022 04:20
-
-
Save mym0404/c233ed31c9d57ea109c1abaa682ed8fd 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
n = int(input()) | |
h = [int(input()) for _ in range(n)] | |
h.append(10 ** 20) | |
n += 1 | |
answer = 0 | |
stack = [] | |
for i in range(n): | |
while len(stack) and stack[-1][0] <= h[i]: | |
answer += i - stack[-1][1] - 1 | |
stack.pop() | |
stack.append([h[i], i]) | |
print(answer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment