Advertisement
orazovm

Untitled

Nov 20th, 2016
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.00 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. #define ff first
  4. #define ss second
  5. #define pp pop_back
  6. #define mp make_pair
  7. #define pb push_back
  8. #define lld long long
  9. #define mid(x, y) (x+y)/2
  10. #define pii pair <int, int>
  11. #define sz(x) (int)x.size()
  12. #define gcd(x, y) __gcd (x, y)
  13. #define all(x) x.begin(), x.end()
  14. #define foreach(i, x) for(auto i: x)
  15. #define lcm(x, y) (x*y) / __gcd (x, y)
  16. #define random srand((unsigned)time(NULL))
  17.  
  18. using namespace std;
  19.  
  20. const int S = 317;
  21. const int Base = 27;
  22. const int N = 1e6+6;
  23. const int Max = 1e5+5;
  24. const int Mod = 1e9+7;
  25. const int inf = 1<<30;
  26.  
  27. int n;
  28. stack< int > s;
  29. int a[Max], ans[Max];
  30.  
  31. int main() {
  32.     scanf("%d", &n);
  33.     for(int i=1; i<=n; i++)
  34.         scanf("%d", &a[i]);
  35.  
  36.     for(int i=n; i>=1; i--) {
  37.         while(!s.empty() && a[i] < a[s.top()])
  38.             ans[s.top()] = s.top()-i-1, s.pop();
  39.         s.push(i);
  40.     }
  41.     while(!s.empty())
  42.         ans[s.top()] = s.top()-1, s.pop();
  43.  
  44.     for(int i=1; i<=n; i++)
  45.         printf("%d ", ans[i]);
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement