Submission #596772

# Submission time Handle Problem Language Result Execution time Memory
596772 2022-07-15T04:05:15 Z Cookie XORanges (eJOI19_xoranges) C++14
100 / 100
177 ms 16116 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define vt vector
#define pb push_back
const int mxn = 2e5 + 3;
ll a[mxn];
int n, q;
ll odd[mxn * 4] = {}, even[mxn * 4] = {};
void build(int nd, int l, int r){
    if(l == r){
        if(l % 2 == 0)even[nd] = a[l];
        else odd[nd] = a[l];
        return;
    }
    int mid = (l + r) >> 1;
    build((nd << 1), l, mid); build((nd << 1) + 1, mid + 1, r);
    odd[nd] = odd[(nd << 1)] ^ odd[(nd << 1) + 1]; even[nd] = even[(nd << 1)] ^ even[(nd << 1) + 1];
}
void upd(int nd, int l, int r, int id, ll v){
    if(id > r || id < l)return;
    if(l == r){
        even[nd] = v;
        return;
    }
    int mid = (l + r) >> 1;
    upd((nd << 1), l, mid, id, v); upd((nd << 1) + 1, mid + 1, r, id, v);
     even[nd] = even[(nd << 1)] ^ even[(nd << 1) + 1];
}
void upd2(int nd, int l, int r, int id, ll v){
    if(id > r || id < l)return;
    if(l == r){
        odd[nd] = v;
        return;
    }
    int mid = (l + r) >> 1;
    upd2((nd << 1), l, mid, id, v); upd2((nd << 1) + 1, mid + 1, r, id, v);
     odd[nd] = odd[(nd << 1)] ^ odd[(nd << 1) + 1];
}
ll get(int nd, int l, int r, int ql, int qr){
    if(ql > r || qr < l)return(0);
    if(ql <= l && qr >= r)return(even[nd]);
    int mid = (l + r) >> 1;
    return(get((nd << 1), l, mid, ql, qr) ^ get((nd << 1) + 1, mid + 1, r, ql,qr));
}
ll get2(int nd, int l, int r, int ql, int qr){
    if(ql > r || qr < l)return(0);
    if(ql <= l && qr >= r)return(odd[nd]);
    int mid = (l + r) >> 1;
    return(get2((nd << 1), l, mid, ql, qr) ^ get2((nd << 1) + 1, mid + 1, r, ql,qr));
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> q;
	for(int i = 1; i <= n; i++)cin >> a[i];
    build(1, 1, n);
	for(int i = 0; i < q; i++){
	    int qq; cin >> qq;
	    if(qq == 1){
	        int id; cin >> id; ll x; cin >> x;
	        if(id % 2 == 0){
	            upd(1, 1, n, id, x);
	        }else{
	            upd2(1, 1, n, id, x);
	        }
	        a[id] = x;
	    }else{
	        int l, r; cin >> l >> r;
	        if((r - l + 1) % 2 == 0)cout << 0 << "\n";
	        else{
	            if(l % 2 == 0){
	                cout << get(1, 1, n, l, r) << "\n";
	            }else{
	                cout << get2(1, 1, n, l, r) << "\n";
	            }
	        }
	    }
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 3 ms 652 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
14 Correct 3 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 134 ms 15868 KB Output is correct
2 Correct 140 ms 16100 KB Output is correct
3 Correct 122 ms 16116 KB Output is correct
4 Correct 113 ms 15680 KB Output is correct
5 Correct 112 ms 15748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 3 ms 652 KB Output is correct
13 Correct 3 ms 596 KB Output is correct
14 Correct 3 ms 596 KB Output is correct
15 Correct 134 ms 15868 KB Output is correct
16 Correct 140 ms 16100 KB Output is correct
17 Correct 122 ms 16116 KB Output is correct
18 Correct 113 ms 15680 KB Output is correct
19 Correct 112 ms 15748 KB Output is correct
20 Correct 131 ms 15872 KB Output is correct
21 Correct 133 ms 15784 KB Output is correct
22 Correct 177 ms 15968 KB Output is correct
23 Correct 110 ms 15752 KB Output is correct
24 Correct 120 ms 15744 KB Output is correct