-
-
Save fredbr/8d6c3e24c26fecf4a7d3884a8e782959 to your computer and use it in GitHub Desktop.
Torres
This file contains 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
#include <bits/stdc++.h> | |
using namespace std; | |
const int maxn = 1000010; | |
int v[maxn]; | |
int main() | |
{ | |
ios_base::sync_with_stdio(false); | |
cin.tie(0); | |
int n; | |
cin >> n; | |
stack<int> s; | |
for (int i = 0; i < n; i++) { | |
cin >> v[i]; | |
while (s.size() > 0 and v[s.top()] <= v[i]) s.pop(); | |
int ans = 0; | |
if (s.empty()) ans = i; | |
else ans = i-s.top(); | |
cout << ans << " "; | |
s.push(i); | |
} | |
cout << "\n"; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment