This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vll vector<long long>
#define MOD 1000000007
#define endl '\n'
typedef long long ll;
void print(vi v){
cout<<"Contents of vector:\n";
for(auto x : v) cout<<x<<" ";
cout<<endl<<endl;
}
const int MAXN = 200009;
int ar[MAXN];
int n;
int fenodd[MAXN] = {0};
int feneven[MAXN] = {0};
void updodd(int p, int x) {
for (int i = p; i < MAXN; i += i&(-i))
fenodd[i] ^= x;
}
int getodd(int p) {
// gauna sumą elementų nuo 1-ojo iki p-tojo
int ret = 0;
for (int i = p; i > 0; i -= i&(-i))
ret ^= fenodd[i];
return ret;
}
int getodd (int l, int r) {
// gauna sumą elementų, kurių indeksai intervale [l; r]
//cout<<"Getting "<<r<<" and "<<l<<endl;
return getodd(r) ^ getodd(l-1);
}
void updeven(int p, int x) {
for (int i = p; i < MAXN; i += i&(-i))
feneven[i] ^= x;
}
int geteven(int p) {
int ret = 0;
for (int i = p; i > 0; i -= i&(-i))
ret ^= feneven[i];
return ret;
}
int geteven(int l, int r) {
//cout<<"R: "<<r<<" L: "<<l-1<<endl;
return geteven(r) ^ geteven(l-1);
}
void solve(){
int q; cin>>n>>q;
for(int i = 0; i<n; i++) cin>>ar[i];
//cerr<<"0 0 "<<endl;
//updodd(0, 0);
//cerr<<"10101"<<endl;
//updeven(0, 0);
updodd(1, ar[0]);
updeven(1, ar[1]);
for(int i = 4; i<=n; i+=2) {
updeven((i+1)/2, ar[i-1]);
}
for(int i = 3; i<=n; i+=2) {
//cout<<"Updating "<<i<<endl;
updodd((i+1)/2, ar[i-1]);
}
/*cout<<"Prefsodd: "<<endl;
for(int i = 0; i<=n; i++) cout<<getodd(i)<<" ";
cout<<endl<<endl;*/
/*cout<<"Prefseven: "<<endl;
for(int i = 0; i<=n; i++) cout<<geteven(i)<<" ";
cout<<endl<<endl;*/
for(int i = 0; i<q; i++){
int type; cin>>type;
if(type == 1){
int ind, value; cin>>ind>>value;
//cout<<"Updating "<<(ind+1)/2<<endl;
if(ind%2) {
updodd((ind+1)/2, getodd((ind+1)/2, (ind+1)/2));
updodd((ind+1)/2, value);
} else {
updeven((ind+1)/2, geteven((ind+1)/2, (ind+1)/2));
updeven((ind+1)/2, value);
}
/*cout<<"Prefsodd: "<<endl;
for(int i = 0; i<=n; i++) cout<<getodd(i)<<" ";
cout<<endl<<endl;*/
} else {
int from, to; cin>>from>>to;
if((to-from+1)%2 == 0){
cout<<"0"<<endl;
continue;
}
if(from%2) {
cout<<getodd(max(1, (from+1)/2), (to+1)/2)<<endl;
} else {
cout<<geteven(max(1, (from+1)/2), (to+1)/2)<<endl;
}
}
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
//ifstream cin("input.txt"); ofstream cout("output.txt");///cia failai
//int T; cin>>T;
int T = 1;
for(int it = 1; it<=T; it++){
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |