ProgMe

Untitled

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