Advertisement
Ahmed_Negm

Untitled

Sep 30th, 2022
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/assoc_container.hpp>
  3. #include <ext/pb_ds/tree_policy.hpp>
  4. using namespace std;
  5. using namespace __gnu_pbds;
  6. #define ll long long
  7. #define ull unsigned long long
  8. #define nl '\n'
  9. #define sz(x) int(x.size())
  10. #define all(x) x.begin(),x.end()
  11. #define rall(s)  s.rbegin(), s.rend()
  12. #define getline(s) getline(cin>>ws,s)
  13. #define ceill(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  14. #define pi  3.141592653589793
  15. #define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
  16. #define multi_ordered_set tree<pair<ll,ll>, null_type,less_equal<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update>
  17.  
  18.  
  19. void Fast_IO(){
  20. ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  21. // freopen("filename.in", "r", stdin);
  22. // freopen("filename.txt", "w", stdout);
  23. #ifndef ONLINE_JUDGE
  24. freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  25. #endif
  26. }
  27.  
  28. int dx[8] = { 2, 1, -1, -2, -2, -1, 1, 2 };
  29. int dy[8] = { 1, 2, 2, 1, -1, -2, -2, -1 };
  30.  
  31.  
  32.  
  33.  
  34.  
  35. void solve(){
  36. multi_ordered_set st;
  37. ll n,q; cin>>n>>q;
  38. vector<ll> v(n);
  39. for(int i=0;i<n;i++) {
  40.     cin >> v[i];
  41. st.insert({v[i],i});
  42. }
  43.  
  44. while(q--){
  45.     char c; ll x,y; cin>>c>>x>>y;
  46.     if(c=='?'){
  47.         cout<<st.order_of_key({y+1,0})-st.order_of_key({x,0})<<nl;
  48.     }else{
  49.         --x;
  50.         st.erase({ v[x], x });
  51.         v[x]=y;
  52.         st.insert({v[x],x});
  53.     }
  54. }
  55.  
  56.  
  57.  
  58.  
  59. }
  60.  
  61. int main(){
  62.     Fast_IO();
  63. int t =1;
  64. //cin>>t;
  65. while(t--){
  66. solve();
  67. }
  68. return 0;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement