답안 #634361

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
634361 2022-08-24T09:38:24 Z smartmonky XORanges (eJOI19_xoranges) C++14
100 / 100
511 ms 11328 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <set>
#include <map>
 
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define int ll
using namespace std;
const int N=3e5;
ll t[2][N*4],a[N],n;
void build(int v=1,int tl=1,int tr=n){
	if(tl==tr){
	//	cout << (tl&1) <<" " <<v  <<" "<< a[tl]<<endl;
		t[(tl & 1)][v]=a[tl];
	}else{
		int mid=(tl+tr) >> 1;
		build(v*2,tl,mid);
		build(v*2+1,mid+1,tr);
	t[1][v]=(t[1][v*2]^t[1][v*2+1]);
	t[0][v]=(t[0][v*2]^t[0][v*2+1]);
	}
}
void upd(int pos,int val,int v=1, int tl=1,int tr=n){
	if(tl==tr){
		t[(tl & 1)][v]=val;
	}else{
		int mid=(tl+tr) >> 1;
		if(pos<=mid)
			upd(pos,val,v*2,tl,mid);
		else
			upd(pos,val,v*2+1,mid+1,tr);
	t[1][v]=(t[1][v*2]^t[1][v*2+1]);
	t[0][v]=(t[0][v*2]^t[0][v*2+1]);
	}
}
int get(int l,int r,int v=1,int tl=1,int tr=n){
	 if (l > tr || tl > r)
		return 0;
	if (l <= tl && tr <= r)
		return t[(l & 1)][v];
	int mid=(tl+tr) >> 1;
	return get(l,r,v*2,tl,mid)^get(l,r,v*2+1,mid+1,tr);
}
main(){
    int q;
    cin >> n>>q;
    for(int i=1;i<=n;i++)
		cin >>a[i];
	build();

	while(q--){
		int type,x,y;
		cin >>type >>x >>y;
		if(type==1)
			upd(x,y);
		else{
			if((y-x+1)%2==0)
				cout<<0<<endl;
			else
				cout <<get(x,y)<<endl;
		}
	}
}

Compilation message

xoranges.cpp:50:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   50 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 8 ms 596 KB Output is correct
12 Correct 9 ms 596 KB Output is correct
13 Correct 13 ms 628 KB Output is correct
14 Correct 13 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 511 ms 11328 KB Output is correct
2 Correct 485 ms 11264 KB Output is correct
3 Correct 499 ms 11244 KB Output is correct
4 Correct 467 ms 11280 KB Output is correct
5 Correct 489 ms 11208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 8 ms 596 KB Output is correct
12 Correct 9 ms 596 KB Output is correct
13 Correct 13 ms 628 KB Output is correct
14 Correct 13 ms 596 KB Output is correct
15 Correct 511 ms 11328 KB Output is correct
16 Correct 485 ms 11264 KB Output is correct
17 Correct 499 ms 11244 KB Output is correct
18 Correct 467 ms 11280 KB Output is correct
19 Correct 489 ms 11208 KB Output is correct
20 Correct 379 ms 10572 KB Output is correct
21 Correct 380 ms 10608 KB Output is correct
22 Correct 383 ms 10572 KB Output is correct
23 Correct 459 ms 11208 KB Output is correct
24 Correct 458 ms 11100 KB Output is correct