IMohammedNasr

I. Playing With Houses V2 (hard-version)

Sep 24th, 2022
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.42 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #include <ext/pb_ds/assoc_container.hpp>
  4. #include <ext/pb_ds/tree_policy.hpp>
  5. using namespace __gnu_pbds;
  6. #define cin(v) for (auto &i : v) cin >> i;
  7. #define cout(v) for (auto &i : v) cout << i << " "; cout<<'\n';
  8. #define ll long long
  9. #define all(v) v.begin(), v.end()
  10. #define rall(v) v.rbegin(), v.rend()
  11. #define MOD 1000000007
  12. #define Ceil(a,b) a / b + (a % b != 0)
  13. #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs"<< "\n";
  14. #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
  15. #define multi_ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
  16.  
  17. void Warding()
  18. {
  19.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  20. #ifndef ONLINE_JUDGE
  21.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  22. #endif
  23. }
  24.  
  25. /*
  26. STOP USING int  
  27. */
  28.  
  29.  
  30.  
  31. void solve(){
  32.     int n; cin>>n;
  33.     vector<int> v(n);
  34.     deque<int> ans;
  35.     multi_ordered_set st;
  36.     for(int i=0; i < n; i++){
  37.         cin>>v[i];
  38.     }
  39.     st.insert(v[n-1]);
  40.     for(int i=n-2; i>=0; i--){
  41.         ans.push_front(st.size() - st.order_of_key(v[i] + 1));
  42.         st.insert(v[i]);
  43.     }
  44.     ans.push_back(0);
  45.     cout(ans);
  46. }
  47.  
  48. int main()
  49. {
  50.     Warding();
  51.     int TC = 1;
  52.     // cin >> TC;
  53.     while (TC--)
  54.     {
  55.         solve();
  56.     }
  57.     Time
  58. }
Add Comment
Please, Sign In to add comment