subtask 1,2,3wa 4tle
感觉上思路和题解没有啥大区别
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 1;
int n, m;
//奇数位的前缀和树,偶数位的前缀和树
int t1[N], t2[N], x[N];
int lowbit(int x){
return x & (-x);
}
int sum(int t[], int x){
int res = 0;
for(int i = x; i; i -= lowbit(x)) res ^= t[i];
return res;
}
void add(int t[], int x, int k){
for(int i = x; i <= n; i += lowbit(x)) t[i] ^= k;
}
signed main(){
cin >> n >> m;
int a, b, c;
for(int i = 1; i <= n; i ++){
cin >> x[i];
if(i % 2) add(t1, i, x[i]);
else add(t2, i, x[i]);
}
for(int i = 1; i <= m; i ++){
cin >> a >> b >> c;
if(a == 1){
//利用异或性质,先传原数,再传新数
if(b % 2) add(t1, b, x[b]), add(t1, b, c), x[b] = c;
else add(t2, b, x[b]), add(t2, b, c), x[b] = c;
}
if(a == 2){
if(b > c) swap(b, c);
//区间长度为偶数,每个数被区间涵盖的次数均为偶数,异或和为零
if((c - b + 1) % 2 == 0){
cout << 0 << endl;
continue;
} else{
if(b % 2) cout << (sum(t1, c) ^ sum(t1, b - 1)) << endl;
else cout << (sum(t2, c) ^ sum(t2, b - 1)) << endl;
}
}
}
return 0;
}