Skip to content

Instantly share code, notes, and snippets.

@fredbr
Created May 3, 2018 00:03
Show Gist options
  • Save fredbr/8d6c3e24c26fecf4a7d3884a8e782959 to your computer and use it in GitHub Desktop.
Save fredbr/8d6c3e24c26fecf4a7d3884a8e782959 to your computer and use it in GitHub Desktop.
Torres
#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