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;
}
void solve(){
int n, q; cin>>n>>q;
int ar[n], prefeven[n+1] = {0}, prefodd[n+1] = {0};
for(int i = 0; i<n; i++) cin>>ar[i];
prefodd[0] = 0;
prefeven[0] = 0;
prefodd[1] = ar[0];
prefeven[2] = ar[1];
for(int i = 4; i<=n; i+=2) {
prefeven[i] = prefeven[i-2] ^ ar[i-1];
}
for(int i = 3; i<=n; i+=2) {
prefodd[i] = prefodd[i-2] ^ ar[i-1];
//cout<<i<<" is equal to "<<prefodd[i-2]<<" xor "<<ar[i-1]<<endl;
}
/*cout<<"Prefsodd: "<<endl;
for(int i = 0; i<=n; i++) cout<<prefodd[i]<<" ";
cout<<endl<<endl;
cout<<"Prefseven: "<<endl;
for(int i = 0; i<=n; i++) cout<<prefeven[i]<<" ";
cout<<endl<<endl;*/
for(int i = 0; i<q; i++){
int type; cin>>type;
if(type == 1){
int ind, value; cin>>ind>>value;
ar[ind-1] = value;
/*cout<<"array: "<<endl;
for(int i = 0; i<=n; i++) cout<<ar[i]<<" ";
cout<<endl<<endl;*/
prefodd[0] = 0;
prefeven[0] = 0;
prefodd[1] = ar[0];
prefeven[2] = ar[1];
for(int i = 4; i<=n; i+=2) {
prefeven[i] = prefeven[i-2] ^ ar[i-1];
}
for(int i = 3; i<=n; i+=2) {
prefodd[i] = prefodd[i-2] ^ ar[i-1];
//cout<<i<<" is equal to "<<prefodd[i]<<" of "<<prefodd[i-2]<<" xor "<<ar
}
/*cout<<"Prefsodd: "<<endl;
for(int i = 0; i<=n; i++) cout<<prefodd[i]<<" ";
cout<<endl<<endl;*/
} else {
int from, to; cin>>from>>to;
if((to-from+1)%2 == 0){
cout<<"0"<<endl;
continue;
}
int ans = 0;
if(from%2) {
if(from != 1) ans = prefodd[to] ^ prefodd[from-2];
else ans = prefodd[to] ^ 0;
//cout<<"odd"<<endl;
} else {
ans = prefeven[to] ^ prefeven[from-2];
}
/*cout<<"Map: "<<endl;
for(auto x : m){
cout<<x.first<<" : "<<x.second<<endl;
}*/
cout<<ans<<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... |