Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include<iostream>
- #include <algorithm>
- #include <cmath>
- #include <iomanip>
- #include <fstream>
- #include <string>
- #include <set>
- #include <deque>
- #include <queue>
- #include <map>
- #include <bitset>
- #include <random>
- #include <cassert>
- #include <unordered_map>
- #include <unordered_set>
- #include<math.h>
- using namespace std;
- typedef unsigned int ui;
- typedef long long ll;
- typedef unsigned long long ull;
- typedef long double ld;
- #define endl "\n"
- #define all(a) a.begin(), a.end()
- #define allr(a) a.rbegin(), a.rend()
- #define pb push_back
- #define pikachu push_back
- #define F first
- #define S second
- const ll MAXN = 1e5+1;
- struct segtree {
- ll ind;
- ll cnt[8];
- };
- segtree add[MAXN];
- segtree t[4 * MAXN];
- ll a[MAXN];
- ll n;
- void build(ll v, ll tl, ll tr) {
- if (tl == tr) {
- t[v].cnt[a[tl]]++;
- t[v].ind = a[tl];
- }
- else {
- ll tm = (tl + tr) / 2;
- build(v * 2, tl, tm);
- build(v * 2 + 1, tm + 1, tr);
- for (int i = 0; i <= 7; i++) {
- t[v].cnt[i] = t[v * 2].cnt[i] + t[v * 2 + 1].cnt[i];
- }
- }
- }
- void update(ll v, ll tl, ll tr, ll l, ll r, ll color) {
- if (l > r)
- return;
- if (l == tl && tr == r) {
- for (ll i = 0; i <= 8; i++) {
- if (t[v].cnt[i]) {
- t[v].cnt[i]--;
- t[v].cnt[i ^ color]++;
- }
- }
- }
- else {
- ll tm = (tl + tr) / 2;
- update(v * 2, tl, tm, l, min(r, tm), color);
- update(v * 2 + 1, tm + 1, tr, max(l, tm + 1), r, color);
- for (int i = 0; i <= 8; i++) {
- t[v].cnt[i] = t[2 * v].cnt[i] + t[2 * v + 1].cnt[i];
- }
- }
- }
- ll quee(ll v, ll vl, ll vr, ll l, ll r,ll x) {
- if (r < vl || vr < l)
- return 0;
- if (l <= vl && vr <= r)
- return t[v].cnt[x];
- ll vm = vl + (vr - vl) / 2;
- ll ql = quee(2 * v, vl, vm, l, r, x);
- ll qr = quee(2 * v + 1, vm + 1, vr, l, r, x);
- return ql + qr;
- }
- ll ask(ll l, ll r, ll x) {
- ll no = 1e9+9;
- if (r == no || l == no) {
- return no;
- }
- while (r - l > 1) {
- ll mid = r + l;
- mid /= 2;
- if (quee(1, 0, n - 1, l, mid,x)) {
- r = mid;
- }
- else if (quee(1, 0, n - 1, mid+1, r, x)) {
- l = mid;
- }
- else {
- return no;
- }
- }
- if (r < l) {
- return no;
- }
- return l;
- }
- void solve() {
- ll n;
- cin >> n;
- ll q;
- cin >> q;
- for (ll i = 0; i < n; i++) {
- cin >> a[i];
- }
- build(1, 0, n - 1);
- for (ll i = 0; i < q; i++) {
- string ques;
- cin >> ques;
- if (ques == "xor") {
- ll l, r, Xor;
- cin >> l >> r >> Xor;
- update(1, 0, n - 1, --l, --r, Xor);
- }
- else {
- ll l, r;
- cin >> l >> r;
- ll siz = r - l + 1;
- r--, l--;
- vector <vector<ll>> dp(siz+1, vector<ll>(8));
- dp[1][0] = ask(l,r, 0);
- for (int i = 1; i <= 7; i++) {
- dp[1][i] = min(dp[1][i - 1], ask(l, r, i-1));
- }
- ll ans = 1;
- for (ll i = 2; i <= siz; i++) {
- for (ll j = 0; j <= 7; j++) {
- if(j>0)dp[i][j] = min(dp[i][j - 1], min(j,ask(dp[i-1][j-1], r, j - 1)));
- if (dp[i][j] != 1e9 + 9) {
- ans = max(ans, dp[i][j]);
- }
- }
- }
- cout << ans << endl;
- }
- }
- }
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- ll t = 1;
- //cin >> t;
- while (t--) {
- solve();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement