답안 #255973

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
255973 2020-08-02T07:24:19 Z tomsyd XORanges (eJOI19_xoranges) C++17
0 / 100
30 ms 15104 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 1e5+1;
vector<int> a(N);

void build(int idx, int l, int r, vector<int>& segt, int rest){
	if (l == r){
		if (l%2 == rest) segt[idx] = a[l];
		return;
	}
	int mid = (l+r)>>1;
	build(2*idx,l,mid,segt,rest);
	build(2*idx+1,mid+1,r,segt,rest);
	segt[idx] = segt[2*idx]^segt[2*idx+1];
}

void modify(int idx, int l, int r, int pos, int val, vector<int>& segt){
	if (r < pos or l > pos) return;
	if (l == r){
		segt[idx] = val;
		return;
	}
	int mid = (l+r)>>1;
	modify(2*idx,l,mid,pos,val,segt);
	modify(2*idx+1,mid+1,r,pos,val,segt);
	segt[idx] = segt[2*idx]^segt[2*idx+1];
}

int query(int idx, int l, int r, int L, int R, vector<int>& segt){
	if (r < L or l > R) return 0;
	if (l >= L and r <= R) return segt[idx];
	int mid = (l+r)>>1;
	return query(2*idx,l,mid,L,R,segt)^query(2*idx+1,mid+1,r,L,R,segt);
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,q;
	cin >> n >> q;
	vector<int> odd(4*n+5), even(4*n+5);
	for (int i=0; i<n; ++i){
		cin >> a[i];
	}
	build(1,0,n-1,even,0);
	build(1,0,n-1,odd,1);
	for (int i=0; i<q; ++i){
		int type;
		cin >> type;
		if (type == 1){
			int pos, val;
			cin >> pos >> val;
			pos--;
			if (pos%2 == 0) modify(1,0,n-1,pos,val,even);
			else modify(1,0,n-1,pos,val,odd);
		}
		else{
			int l,r;
			cin >> l >> r;
			l--; r--;
			int ans = 0;
			if ((r-l+1)%2 == 0){
				if (l%2 == 0) ans = query(1,0,n-1,l,r,odd);
				else ans = query(1,0,n-1,l,r,even);
			}
			else{
				if (l%2 == 0) ans = query(1,0,n-1,l,r,even);
				else ans = query(1,0,n-1,l,r,odd);
			}
			cout << ans << '\n';
		}
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 30 ms 15104 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 768 KB Output isn't correct
2 Halted 0 ms 0 KB -