Submission #925437

# Submission time Handle Problem Language Result Execution time Memory
925437 2024-02-11T15:50:53 Z Karoot XORanges (eJOI19_xoranges) C++17
100 / 100
277 ms 12040 KB
#include <iostream>
#include <cmath>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <iomanip>
#include <algorithm>

#define all(x)  (x).begin(), (x).end()
#define rall(x)  (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;

ll linf = 1e15+1;

inline void scoobydoobydoo(){
    ios::sync_with_stdio(false);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
}

const int MAXN = 2e5+3;
ll vals[MAXN];

ll oddBIT[MAXN], evenBIT[MAXN];

void update(int node, ll val, bool isOdd){
    val ^= vals[node];
    while (node < MAXN){
        if (isOdd)oddBIT[node] ^= val;
        else evenBIT[node] ^= val;
        node += node&(~node+1);
    }
}

ll query(int l, int r, bool isOdd){
    ll over = 0;
    while (r){
        if (isOdd)over ^= oddBIT[r];
        else over ^= evenBIT[r];
        r -= r&(~r+1);
    }

    //cout << "over: " << over << endl;

    ll under = 0;
    l--;
    while (l){
        if (isOdd)under ^= oddBIT[l];
        else under ^= evenBIT[l];
        l -= l&(~l+1);
    }
    return over^under;
}



int main(){
    scoobydoobydoo();
    int n, q; cin >> n >> q;
    for (int i = 1; i <= n; i++){
        cin >> vals[i];
        update(i, 0, i%2);
    }

    /*for (int i = 1; i <= 2*n; i++){
        cout << i << ": " << oddBIT[i] << " " << evenBIT[i] << endl;
    }*/

    vector<int> ans;

    while (q--){
        int t; cin >> t;
        if (t == 1){
            int i, v; cin >> i >> v;
            update(i, v, i%2);
            vals[i] = v;
        } else {
            int l, r; cin >> l >> r;
            if ((r-l+1)%2 == 0)ans.push_back(0);
            else if (l == r)ans.push_back(vals[l]);
            else ans.push_back(query(l, r, r%2));
            //cout << query(l, r, l%2) << endl;
        }
    }

    for (ll x : ans)cout << x << endl;




    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4556 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4444 KB Output is correct
4 Correct 1 ms 4564 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4556 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 1 ms 4564 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 5 ms 4700 KB Output is correct
12 Correct 6 ms 4700 KB Output is correct
13 Correct 7 ms 4700 KB Output is correct
14 Correct 7 ms 4952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 276 ms 11908 KB Output is correct
2 Correct 277 ms 11980 KB Output is correct
3 Correct 274 ms 12040 KB Output is correct
4 Correct 274 ms 11968 KB Output is correct
5 Correct 275 ms 11724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4556 KB Output is correct
6 Correct 2 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 2 ms 4444 KB Output is correct
9 Correct 1 ms 4564 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 5 ms 4700 KB Output is correct
12 Correct 6 ms 4700 KB Output is correct
13 Correct 7 ms 4700 KB Output is correct
14 Correct 7 ms 4952 KB Output is correct
15 Correct 276 ms 11908 KB Output is correct
16 Correct 277 ms 11980 KB Output is correct
17 Correct 274 ms 12040 KB Output is correct
18 Correct 274 ms 11968 KB Output is correct
19 Correct 275 ms 11724 KB Output is correct
20 Correct 169 ms 11388 KB Output is correct
21 Correct 172 ms 11352 KB Output is correct
22 Correct 169 ms 11216 KB Output is correct
23 Correct 262 ms 11684 KB Output is correct
24 Correct 260 ms 11728 KB Output is correct