Advertisement
Saleh127

CSES 1645

Apr 17th, 2021
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5. int main()
  6. {
  7. ios_base::sync_with_stdio(0);
  8. cin.tie(0);cout.tie(0);
  9.  
  10.  
  11. vector<pair<ll,ll>>x;
  12.  
  13. ll n,m,i,j,k,l=0;
  14.  
  15. cin>>n;
  16.  
  17. for(i=1;i<=n;i++)
  18. {
  19. cin>>k;
  20.  
  21. l=0;
  22. while(x.size())
  23. {
  24. if(x.back().first>=k)
  25. {
  26. x.pop_back();
  27. }
  28. else
  29. {
  30. l=x.back().second;
  31. break;
  32. }
  33. }
  34. if(i==n) cout<<l<<endl;
  35. else cout<<l<<" ";
  36.  
  37. x.push_back({k,i});
  38. }
  39.  
  40. return 0;
  41. }
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement