求助38 pts(WA on Subtask 1,3,5)
查看原帖
求助38 pts(WA on Subtask 1,3,5)
891150
403notfound楼主2023/10/16 20:14
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n , p , a[200005] , len1 , len0 , t0[200005] , t1[200005];
ll op , x , y;
void add(ll x , ll y, ll *c){
 	if (x % 2 == 1){
 		ll v = x;
 		x ++ , x /= 2;
 		while(x <= len1){
 			c[x] ^= a[v];
 			c[x] ^= y;
 			x += (x & -x);
 		}
 	}   
 	else {
 		ll v = x;
 		x /= 2;
 		while(x <= len0){
  			c[x] ^= a[v];
 			c[x] ^= y;
 			x += (x & -x);
 		}
 	}
}
ll sum(ll x){
 	ll tot = 0;
 	if (x % 2 == 0){
 		x /= 2;
 		while (x){
  			tot ^= t0[x];
 			x -= (x & -x);
 		}
 	}
 	else {
 		x ++ , x /= 2;
 		while(x){
 			tot ^= t1[x];
 			x -= (x & -x);
  		}
 	}
 	return tot;
}
int main(){
 	scanf("%lld%lld",&n,&p);
 	len1 = (n + 1) / 2 , len0 = n / 2;
 	for (ll i = 1;i <= n;i++) scanf("%lld",&a[i]);
  	for (ll i = 1;i <= n;i++){
 		ll j = (i + 1) / 2;
 		if (i % 2 == 0){
 			t0[j] ^= a[i];
 			ll k = j + (j & -j);
 			if (k <= len0) t0[k] ^= t0[j];
 		}
 		else {
  			t1[j] ^= a[i];
 			ll k = j + (j & -j);
 			if (k <= len1) t1[k] ^= t1[j];
 		}
 	}
 	while (p--){
 		scanf("%lld%lld%lld",&op,&x,&y);
  		if (op == 1){
 			if (x % 2 == 1) add(y , a[x] , t1) , a[x] = y;
 			else add(y , a[x] , t0) , a[x] = y;
 		}
   		else {
 			if ((x - y) % 2 != 0){
 				cout << 0 << endl;
 	 		}
 			else {
 				cout << (sum(y) ^ sum(x - 2)) << endl;
 			}
 		}
 	}
 	return 0;
}   
2023/10/16 20:14
加载中...