ProgMe

Untitled

Jan 15th, 2021
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.08 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int32_t main()
  6. {
  7. ios::sync_with_stdio(false);
  8. cin.tie(nullptr); cout.tie(nullptr);
  9. int n, q;
  10. cin >> n >> q;
  11. vector <int> a(n);
  12. for(auto &i: a)
  13. cin >> i;
  14. vector<multiset<int>> v (8);
  15. for(int i = 0; i < n; i++)
  16. v[a[i]].insert(i);
  17. while(q--){
  18. string s;
  19. cin >> s;
  20. if(s == "xor"){
  21. int l, r, u;
  22. cin >> l >> r >> u;
  23. l--, r--;
  24. for(int i = l; i <= r; i++){
  25. v[a[i]].erase(i);
  26. a[i] ^= u;
  27. v[a[i]].insert(i);
  28. }
  29. }
  30. else{
  31. int l, r;
  32. cin >> l >> r;
  33. l--, r--;
  34. int ans = 0;
  35. for(int i = 0; i <= 7; i++) {
  36. if(v[i].lower_bound(l) == v[i].end())
  37. continue;
  38. int now_z = *v[i].lower_bound(l);
  39. if(now_z > r)
  40. continue;
  41. ans = max(ans, 1);
  42. for (int j = i + 1; j <= 7; j++){
  43. if(v[j].upper_bound(now_z) == v[j].end())
  44. continue;
  45. int now_o = *v[j].upper_bound(now_z);
  46. if(now_o > r)
  47. continue;
  48. ans = max(ans, 2);
  49. for(int k = j + 1; k <= 7; k++){
  50. if(v[k].upper_bound(now_o) == v[k].end())
  51. continue;
  52. int now_two = *v[k].upper_bound(now_o);
  53. if(now_two > r)
  54. continue;
  55. ans = max(ans, 3);
  56. for(int m = k + 1; k <= 7; k++){
  57. if(v[m].upper_bound(now_two) == v[m].end())
  58. continue;
  59. int now_t = *v[m].upper_bound(now_two);
  60. if(now_t > r)
  61. continue;
  62. ans = max(ans, 4);
  63. for(int o = m + 1; o <= 7; o++){
  64. if(v[o].upper_bound(now_t) == v[o].end())
  65. continue;
  66. int now_four = *v[o].upper_bound(now_t);
  67. if(now_four > r)
  68. continue;
  69. ans = max(ans, 5);
  70. for(int p = o + 1; p <= 7; p++){
  71. if(v[p].upper_bound(now_four) == v[p].end())
  72. continue;
  73. int now_f = *v[p].upper_bound(now_four);
  74. if(now_f > r)
  75. continue;
  76. ans = max(ans, 6);
  77. for(int t = p + 1; t <= 7; t++){
  78. if(v[t].upper_bound(now_f) == v[t].end())
  79. continue;
  80. int now_six = *v[t].upper_bound(now_f);
  81. if(now_six > r)
  82. continue;
  83. ans = max(ans, 7);
  84. for(int u = t + 1; u <= 7; u++){
  85. if(v[u].upper_bound(now_six) == v[u].end())
  86. continue;
  87. int now_s = *v[u].upper_bound(now_six);
  88. if(now_s > r)
  89. continue;
  90. ans = max(ans, 8);
  91. }
  92. }
  93. }
  94. }
  95. }
  96. }
  97. }
  98. }
  99. cout << ans << '\n';
  100. }
  101. }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment