Submission #638562

#TimeUsernameProblemLanguageResultExecution timeMemory
638562ShirleyMXORanges (eJOI19_xoranges)C++14
100 / 100
359 ms12064 KiB
#include <bits/stdc++.h> using namespace std; #define int int64_t typedef vector<int> vi; typedef vector<vi> vvi; typedef pair<int,int> ii; typedef vector<ii> vii; typedef vector<vii> vvii; typedef vector<bool> vb; typedef vector<vb> vvb; #define x first #define y second #define pb push_back #define loop(i,s,e) for(int i=s;i<e;i++) #define loopr(i,s,e) for(int i=e-1;i>=s;i--) #define chkmax(a,b) a=max(a,b) #define chkmin(a,b) a=min(a,b) #define all(a) a.begin(),a.end() #define fast {ios_base::sync_with_stdio(false); cin.tie(0);} const int inf = 1e18; const int INF = 1e9; const int mod = 1e9+7; struct seg{ vi a; int sz; bool odd; seg(int n, bool odd) : odd(odd){ for(sz=1;sz<n;sz<<=1); a.resize(2*sz); } void update(int ind, int val){ if((odd && ind%2) || (!odd && ind%2==0)){ ind+=sz; a[ind] = val; for(ind>>=1;ind;ind>>=1) a[ind] = a[2*ind]^a[2*ind+1]; } } int query(int l, int r){ int ans=0; l+=sz; r+=sz; while(l<=r){ if(l%2) ans^=a[l++]; if(r%2==0) ans^=a[r--]; l>>=1; r>>=1; } return ans; } }; int32_t main() { fast; int n,q; cin >> n >> q; seg odd(n, 1), even(n, 0); loop(i,0,n){ int a; cin >> a; odd.update(i,a); even.update(i,a); } loop(i,0,q){ int op; cin >> op; if(op==1){ int ind, val; cin >> ind >> val; ind--; odd.update(ind,val); even.update(ind,val); } else{ int l,r; cin >> l >> r; l--; r--; int ans = 0; if((r-l+1)%2) { if (l % 2) ans = odd.query(l, r); else ans = even.query(l, r); } cout << ans << endl; } } return 0; }
#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...