Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define ff first
- #define ss second
- #define pp pop_back
- #define mp make_pair
- #define pb push_back
- #define lld long long
- #define mid(x, y) (x+y)/2
- #define pii pair <int, int>
- #define sz(x) (int)x.size()
- #define gcd(x, y) __gcd (x, y)
- #define all(x) x.begin(), x.end()
- #define foreach(i, x) for(auto i: x)
- #define lcm(x, y) (x*y) / __gcd (x, y)
- #define random srand((unsigned)time(NULL))
- using namespace std;
- const int S = 317;
- const int Base = 27;
- const int N = 1e6+6;
- const int Max = 1e5+5;
- const int Mod = 1e9+7;
- const int inf = 1<<30;
- int n;
- stack< int > s;
- int a[Max], ans[Max];
- int main() {
- scanf("%d", &n);
- for(int i=1; i<=n; i++)
- scanf("%d", &a[i]);
- for(int i=n; i>=1; i--) {
- while(!s.empty() && a[i] < a[s.top()])
- ans[s.top()] = s.top()-i-1, s.pop();
- s.push(i);
- }
- while(!s.empty())
- ans[s.top()] = s.top()-1, s.pop();
- for(int i=1; i<=n; i++)
- printf("%d ", ans[i]);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement