답안 #237603

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
237603 2020-06-07T16:52:47 Z Pbezz XORanges (eJOI19_xoranges) C++14
100 / 100
213 ms 11396 KB
#include <bits/stdc++.h>
using namespace std;

#define loop(i,n) for (ll i = 0; i < n; i++)

#define ll long long
#define INF 1e9+5
#define MAXN 200007
#define pb push_back 
#define mp make_pair
typedef pair<ll,ll> pii;

ll arr[MAXN];
ll seg[4*MAXN][2];

void recalculate(ll int node){

seg[node][0]=seg[2*node+1][0]^seg[2*node+2][0];

seg[node][1]=seg[2*node+1][1]^seg[2*node+2][1];

}

void build(ll node, ll left, ll right){

	if(left==right){

	if(left%2==0){seg[node][0]=arr[left]; seg[node][1]=0; }
	else{ seg[node][1]=arr[left]; seg[node][0]=0;}

	}else{
	ll middle=(left+right)/2;

	build(2*node+1,left,middle);

	build(2*node+2,middle+1,right);

	recalculate(node);
	}

}

void update(ll node, ll left, ll right, ll x, ll y){

	if(left==right){

	if(left%2==0){seg[node][0]=y; seg[node][1]=0; }
	else{ seg[node][1]=y; seg[node][0]=0;}

	}else{

	ll middle=(left+right)/2;

	if(x<=middle){
		update(2*node+1,left,middle,x,y);
	}else{
		update(2*node+2,middle+1,right,x,y);
	}

	recalculate(node);

	}

}
ll bruh;
ll querie(ll node, ll left, ll right, ll a, ll b){

	if(a<=left&&b>=right)return seg[node][bruh];

	ll middle=(left+right)/2,ans=0;

	if(a<=middle)ans^=querie(2*node+1,left,middle,a,b);

	if(b>=middle+1)ans^=querie(2*node+2,middle+1,right,a,b);

	return ans;

}


int main(){

	ll n,q,type,i,j,l,r;
	cin>>n>>q;

	loop(i,n){
	scanf("%lld",&arr[i+1]);
	}

	build(0,1,n);

	while(q--){

	scanf("%lld",&type);

	if(type==1){

	scanf("%lld%lld",&i,&j);

	arr[i]=j;
	update(0,1,n,i,j);

	}else{

	scanf("%lld%lld",&l,&r);

	if((r-l)%2==1){

	printf("0\n");

	}else{
	bruh=l%2;

	printf("%lld\n",querie(0,1,n,l,r));
}


	}
}

return 0;
}

Compilation message

xoranges.cpp: In function 'int main()':
xoranges.cpp:87:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld",&arr[i+1]);
  ~~~~~^~~~~~~~~~~~~~~~~~
xoranges.cpp:94:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld",&type);
  ~~~~~^~~~~~~~~~~~~~
xoranges.cpp:98:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld",&i,&j);
  ~~~~~^~~~~~~~~~~~~~~~~~
xoranges.cpp:105:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld%lld",&l,&r);
  ~~~~~^~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 9 ms 640 KB Output is correct
12 Correct 8 ms 640 KB Output is correct
13 Correct 9 ms 640 KB Output is correct
14 Correct 8 ms 640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 195 ms 11256 KB Output is correct
2 Correct 195 ms 11260 KB Output is correct
3 Correct 197 ms 11260 KB Output is correct
4 Correct 168 ms 11256 KB Output is correct
5 Correct 166 ms 11256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 9 ms 640 KB Output is correct
12 Correct 8 ms 640 KB Output is correct
13 Correct 9 ms 640 KB Output is correct
14 Correct 8 ms 640 KB Output is correct
15 Correct 195 ms 11256 KB Output is correct
16 Correct 195 ms 11260 KB Output is correct
17 Correct 197 ms 11260 KB Output is correct
18 Correct 168 ms 11256 KB Output is correct
19 Correct 166 ms 11256 KB Output is correct
20 Correct 204 ms 10744 KB Output is correct
21 Correct 213 ms 10744 KB Output is correct
22 Correct 211 ms 10744 KB Output is correct
23 Correct 167 ms 11256 KB Output is correct
24 Correct 169 ms 11396 KB Output is correct