fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int int64_t
  4. #define ll long long
  5. #define el endl;
  6. #define be begin()
  7. #define en end()
  8. #define sz(x) (int)x.size()
  9. #define all(n) n.begin(), n.end()
  10. #define rall(n) n.rbegin(), n.rend()
  11. const int mod = 1e9 + 7, INF = 0x3f3f3f3f, N = 1e2 + 5;
  12.  
  13.  
  14. void RUN()
  15. {
  16. ios_base::sync_with_stdio(false), cout.tie(NULL), cin.tie(NULL);
  17. #ifndef ONLINE_JUDGE
  18. freopen("input.txt", "r", stdin);
  19. freopen("output.txt", "w", stdout);
  20. #endif
  21. }
  22.  
  23. template <typename T> istream& operator>> (istream& in, vector <T> &v)
  24. {
  25. for (auto &i : v) in >> i;
  26. return in;
  27. }
  28.  
  29. void solve()
  30. {
  31. int n; cin >> n;
  32. vector<int> v(n);
  33. cin >> v;
  34. stack<int> st;
  35. for (int i = 0; i < n; i++)
  36. {
  37. while (!st.empty() && v[i] <= v[st.top()]) st.pop();
  38. if (st.empty()) cout << 0 << ' ';
  39. else cout << st.top() + 1 << ' ';
  40. st.push(i);
  41. }
  42. cout << '\n';
  43. }
  44.  
  45. int32_t main()
  46. {
  47. RUN();
  48.  
  49. int T = 1;
  50. // cin >> T;
  51. while (T--) solve();
  52. return 0;
  53. }
Success #stdin #stdout 0.01s 5304KB
stdin
Standard input is empty
stdout