ProgMe

Untitled

Feb 20th, 2021
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #include <ext/pb_ds/tree_policy.hpp>
  3. #include <ext/pb_ds/assoc_container.hpp>
  4.  
  5. #define int int64_t
  6.  
  7. #pragma GCC optimize("O3")
  8.  
  9. using namespace std;
  10. using namespace __gnu_pbds;
  11. using namespace __gnu_cxx;
  12.  
  13. template<typename T>
  14. using orset = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;
  15.  
  16. int32_t main()
  17. {
  18. ios::sync_with_stdio(false);
  19. cin.tie(nullptr); cout.tie(nullptr);
  20. int n, q;
  21. cin >> n >> q;
  22. unordered_map<int, orset<int>> cnt;
  23. vector<int> a(n);
  24. for(int i = 0; i < n; i++){
  25. cin >> a[i];
  26. cnt[a[i]].insert(i);
  27. }
  28. while(q--){
  29. int tp;
  30. cin >> tp;
  31. if(tp == 1){
  32. int i, x;
  33. cin >> i >> x;
  34. i--;
  35. if(a[i] == x)
  36. continue;
  37. cnt[a[i]].erase(i);
  38. if(cnt[a[i]].empty())
  39. cnt.erase(a[i]);
  40. a[i] = x;
  41. cnt[x].insert(i);
  42. }
  43. else{
  44. int l, r, cur = 0;
  45. cin >> l >> r;
  46. l--, r--;
  47. for(auto & i : cnt){
  48. if(i.second.empty())
  49. continue;
  50. int len = i.second.order_of_key(r + 1) - i.second.order_of_key(l);
  51. if(len & 1)
  52. cur++;
  53. }
  54. cout << cur << '\n';
  55. }
  56. }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment