Submission #1131526

#TimeUsernameProblemLanguageResultExecution timeMemory
1131526lopkusXORanges (eJOI19_xoranges)C++20
100 / 100
52 ms6216 KiB
#include <bits/stdc++.h>

#define int long long

using namespace std;

const int N = 2e5 + 5;

struct fenwick{
	vector<int>t;
	void build(int n) {
		t.resize(n + 1);
	}
	void update(int index,int n,int val) {
		while(index <= n) {
			t[index] ^= val;
			index += index & -index;
		}
	}
	int query(int i) {
		int ans = 0;
		while(i > 0) {
			ans ^= t[i];
			i -= i & - i;
		}
		return ans;
	}
}fenw[2];

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, q;
    cin >> n >> q;
    fenw[0].build(n);
    fenw[1].build(n);
    vector<int> a(n + 1);
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
        fenw[i % 2].update(i, n, a[i]);
    }
    while(q--) {
        int o;
        cin >> o;
        if(o == 1) {
            int index, value;
            cin >> index >> value;
            fenw[index % 2].update(index, n, a[index]);
            a[index] = value;
            fenw[index % 2].update(index, n, a[index]);
        }
        else {
            int l, r;
            cin >> l >> r;
            int len = r - l + 1;
            if(len % 2) {
                cout << (fenw[l & 1].query(r) ^ fenw[l & 1].query(l - 1)) << "\n";
            }
            else {
                cout << 0 << "\n";
            }
        }
    }
}

#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...