Submission #999780

#TimeUsernameProblemLanguageResultExecution timeMemory
999780vjudge1XORanges (eJOI19_xoranges)C++17
100 / 100
95 ms15188 KiB
/* :) */ #include <bits/stdc++.h> using namespace std; #define endl '\n' #define ll long long #define pll pair<ll, ll> const int sz = 2e5+5; ll a[sz], b[sz], t[sz*4], t1[sz*4]; void build(ll v, ll l, ll r) { if (l == r){ t[v] = a[l]; t1[v] = b[l]; return; } ll m = (l + r)/2; build(v*2, l, m); build(v*2+1, m+1, r); t[v] = t[v*2] ^ t[v*2+1]; t1[v] = t1[v*2] ^ t1[v*2+1]; } void update(ll v, ll l, ll r, ll ind, ll val) { if (l == r){ t[v] = val; return; } ll m = (l + r)/2; if (ind <= m){ update(v*2, l, m, ind, val); } else { update(v*2+1, m+1, r, ind, val); } t[v] = t[v*2] ^ t[v*2+1]; } void update1(ll v, ll l, ll r, ll ind, ll val) { if (l == r){ t1[v] = val; return; } ll m = (l + r)/2; if (ind <= m){ update1(v*2, l, m, ind, val); } else { update1(v*2+1, m+1, r, ind, val); } t1[v] = t1[v*2] ^ t1[v*2+1]; } ll ans(ll v, ll l, ll r, ll tl, ll tr) { if (l>tr or r<tl) return 0; if (tl<=l and r<=tr) return t[v]; ll m = (l + r)/2; return ans(v*2, l, m, tl, tr) ^ ans(v*2+1, m+1, r, tl, tr); } ll ans1(ll v, ll l, ll r, ll tl, ll tr) { if (l>tr or r<tl) return 0; if (tl<=l and r<=tr) return t1[v]; ll m = (l + r)/2; return ans1(v*2, l, m, tl, tr) ^ ans1(v*2+1, m+1, r, tl, tr); } int main() { ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); ll n, q, k, x; cin>>n>>q; for (ll i = 1; i<=n; i++){ cin>>x; if (i%2==0) b[i] = x; else a[i] = x; } build(1, 1, n); while (q--){ cin>>k; if (k == 1){ ll i, j; cin>>i>>j; if (i%2==0){ update1(1, 1, n, i, j); } else { update(1, 1, n, i, j); } } else { ll l, r; cin>>l>>r; if ((r-l+1)%2==0){ cout<<0<<endl; } else{ if (l%2==0){ cout<<ans1(1, 1, n, l, r)<<endl; } else { cout<<ans(1, 1, n, l, r)<<endl; } } } } }
#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...