답안 #1094012

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1094012 2024-09-28T09:36:50 Z MrNanama XORanges (eJOI19_xoranges) C++17
100 / 100
307 ms 20576 KB
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second

using namespace std;
using ll = long long;

template <typename T> ostream& operator<<(ostream& os, const vector<T>& vec){for (auto itr : vec){os << itr << " ";} return os;}

ll n,q;
vector<ll> arr;
vector<ll> odd;
vector<ll> even;

void upd(ll tar, ll val, vector<ll>& seg){
	ll ind = tar+n;

	seg[ind] = val;
	ind /= 2;

	while(ind){
		seg[ind] = seg[2*ind]^seg[2*ind+1];

		ind /= 2;
	}
}

ll get_val(ll tl, ll tr, vector<ll>& seg){
	ll lo = tl+n; ll hi = tr+n+1;
	ll ans = 0;

	while(lo < hi){
		if(lo & 1){ans ^= seg[lo]; lo++;}
		if(hi & 1){hi--; ans ^= seg[hi];}

		lo/=2; hi/=2;
	}

	return ans;
}

void solve(){
	cin >> n >> q;
	arr.resize(n);
	odd.assign(4*n, 0);
	even.assign(4*n, 0);

	for(ll i=0; i<n; i++){cin >> arr[i];}

	for(ll i=0; i<n; i++){
		if(i%2){
			upd(i,arr[i],odd);
		}else{
			upd(i,arr[i],even);
		}
	}

	for(ll quer=0; quer<q; quer++){
		ll opr;
		cin >> opr;

		if(opr == 1){
			ll tar, val;
			cin >> tar >> val;

			tar--;

			if(tar%2){upd(tar, val, odd);}
			else{upd(tar,val, even);}

		}else{
			ll l,r;
			cin >> l >> r;
			l--; r--;

			if(l % 2 != r % 2){
				cout << 0 << endl;
			}else{
				if(l % 2){
					cout << get_val(l, r, odd) << endl;
				}else{
					cout << get_val(l, r, even) << endl;
				}
			}
		}
	}
}

int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL);

	solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 5 ms 860 KB Output is correct
12 Correct 7 ms 860 KB Output is correct
13 Correct 7 ms 860 KB Output is correct
14 Correct 7 ms 936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 285 ms 20356 KB Output is correct
2 Correct 288 ms 20576 KB Output is correct
3 Correct 307 ms 20560 KB Output is correct
4 Correct 269 ms 20004 KB Output is correct
5 Correct 278 ms 20068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 5 ms 860 KB Output is correct
12 Correct 7 ms 860 KB Output is correct
13 Correct 7 ms 860 KB Output is correct
14 Correct 7 ms 936 KB Output is correct
15 Correct 285 ms 20356 KB Output is correct
16 Correct 288 ms 20576 KB Output is correct
17 Correct 307 ms 20560 KB Output is correct
18 Correct 269 ms 20004 KB Output is correct
19 Correct 278 ms 20068 KB Output is correct
20 Correct 182 ms 20304 KB Output is correct
21 Correct 174 ms 20304 KB Output is correct
22 Correct 174 ms 20248 KB Output is correct
23 Correct 259 ms 20236 KB Output is correct
24 Correct 270 ms 20052 KB Output is correct