답안 #815529

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
815529 2023-08-08T16:36:38 Z ZeroCool XORanges (eJOI19_xoranges) C++14
100 / 100
417 ms 11000 KB
#include <bits/stdc++.h>  
#define INF 1e18
#define LL long long
#define int long long
using namespace std;
	
const int mod = 1e9 + 7;
const int inf = 1e18;
const int mxn = 2e5 + 5;


template<typename T>
struct FenwickTree{
	vector<int> bit;
	int n;
	FenwickTree(int _n){
		n = _n + 69;
		bit.resize(n,0);
	}

	void update(int pos,int val){
		for(;pos<n;pos += pos & -pos)bit[pos] ^= val;
	}

	int query(int pos){
		int ans = 0;
		for(;pos;pos -= pos & -pos)ans ^= bit[pos];
		return ans;
	}

	int range(int l,int r){
		if(l == 1)return query(r);
		return query(r) ^ query(l - 1);
	}
};

     
int A[mxn];

void solve(){
	int n,q;
	cin>>n>>q;

	FenwickTree<size_t> odd(n), even(n);

	for(int i = 1;i<=n;i++)cin>>A[i];
	for(int i = 1;i<=n;i++){
		if(i % 2 == 0){
			even.update(i,A[i]);
		}else{
			odd.update(i, A[i]);
		}
	}
	

	while(q--){
		int o,a,b;
		cin>>o>>a>>b;

		if(o == 1){
			if(a % 2 == 0){
				
				even.update(a,A[a]);
				A[a] = b;
				even.update(a,A[a]);
			}
			else{
				odd.update(a,A[a]);
				A[a] = b;
				odd.update(a,A[a]);
			}
			continue;
		}
	//	cout<<a<<" "<<b<<endl;
		if((b - a + 1) % 2 == 0)cout<<0<<endl;
		else if(a % 2 == 0)cout<<even.range(a,b)<<endl;
		else cout<<odd.range(a,b)<<endl;
	}
}
     
int32_t main() {  
	#ifdef ONLINE_JUDGE
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	#endif
	solve();

	// int  n;
	// cin >>n;
	// FenwickTree fwt(n);

	// int q;
	// cin>>q;
	// while(q--){
	// 	int op;
	// 	cin>>op;

	// 	if(op == 1){
	// 		int pos,val;
	// 		cin>>pos>>val;

	// 		fwt.update(pos,val);
	// 	}else{
	// 		int pos;
	// 		cout<<fwt.query(pos)<<endl;
	// 	}
	// }
}   
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 7 ms 468 KB Output is correct
12 Correct 7 ms 468 KB Output is correct
13 Correct 9 ms 544 KB Output is correct
14 Correct 9 ms 556 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 393 ms 6076 KB Output is correct
2 Correct 417 ms 11000 KB Output is correct
3 Correct 399 ms 10960 KB Output is correct
4 Correct 372 ms 10628 KB Output is correct
5 Correct 374 ms 10700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 2 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 2 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 7 ms 468 KB Output is correct
12 Correct 7 ms 468 KB Output is correct
13 Correct 9 ms 544 KB Output is correct
14 Correct 9 ms 556 KB Output is correct
15 Correct 393 ms 6076 KB Output is correct
16 Correct 417 ms 11000 KB Output is correct
17 Correct 399 ms 10960 KB Output is correct
18 Correct 372 ms 10628 KB Output is correct
19 Correct 374 ms 10700 KB Output is correct
20 Correct 286 ms 10848 KB Output is correct
21 Correct 285 ms 10772 KB Output is correct
22 Correct 297 ms 10736 KB Output is correct
23 Correct 369 ms 10636 KB Output is correct
24 Correct 373 ms 10768 KB Output is correct