Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int32_t main()
- {
- ios::sync_with_stdio(false);
- cin.tie(nullptr); cout.tie(nullptr);
- int n, q;
- cin >> n >> q;
- vector <int> a(n);
- for(auto &i: a)
- cin >> i;
- vector<multiset<int>> v (8);
- for(int i = 0; i < n; i++)
- v[a[i]].insert(i);
- while(q--){
- string s;
- cin >> s;
- if(s == "xor"){
- int l, r, u;
- cin >> l >> r >> u;
- l--, r--;
- for(int i = l; i <= r; i++){
- v[a[i]].erase(i);
- a[i] ^= u;
- v[a[i]].insert(i);
- }
- }
- else{
- int l, r;
- cin >> l >> r;
- l--, r--;
- int ans = 0;
- for(int i = 0; i <= 7; i++) {
- if(v[i].lower_bound(l) == v[i].end())
- continue;
- int now_z = *v[i].lower_bound(l);
- if(now_z > r)
- continue;
- ans = max(ans, 1);
- for (int j = i + 1; j <= 7; j++){
- if(v[j].upper_bound(now_z) == v[j].end())
- continue;
- int now_o = *v[j].upper_bound(now_z);
- if(now_o > r)
- continue;
- ans = max(ans, 2);
- for(int k = j + 1; k <= 7; k++){
- if(v[k].upper_bound(now_o) == v[k].end())
- continue;
- int now_two = *v[k].upper_bound(now_o);
- if(now_two > r)
- continue;
- ans = max(ans, 3);
- for(int m = k + 1; k <= 7; k++){
- if(v[m].upper_bound(now_two) == v[m].end())
- continue;
- int now_t = *v[m].upper_bound(now_two);
- if(now_t > r)
- continue;
- ans = max(ans, 4);
- for(int o = m + 1; o <= 7; o++){
- if(v[o].upper_bound(now_t) == v[o].end())
- continue;
- int now_four = *v[o].upper_bound(now_t);
- if(now_four > r)
- continue;
- ans = max(ans, 5);
- for(int p = o + 1; p <= 7; p++){
- if(v[p].upper_bound(now_four) == v[p].end())
- continue;
- int now_f = *v[p].upper_bound(now_four);
- if(now_f > r)
- continue;
- ans = max(ans, 6);
- for(int t = p + 1; t <= 7; t++){
- if(v[t].upper_bound(now_f) == v[t].end())
- continue;
- int now_six = *v[t].upper_bound(now_f);
- if(now_six > r)
- continue;
- ans = max(ans, 7);
- for(int u = t + 1; u <= 7; u++){
- if(v[u].upper_bound(now_six) == v[u].end())
- continue;
- int now_s = *v[u].upper_bound(now_six);
- if(now_s > r)
- continue;
- ans = max(ans, 8);
- }
- }
- }
- }
- }
- }
- }
- }
- cout << ans << '\n';
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment