답안 #478199

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
478199 2021-10-06T12:21:15 Z pragmatist XORanges (eJOI19_xoranges) C++14
100 / 100
178 ms 11276 KB
#include <bits/stdc++.h>                       
#include <ext/pb_ds/assoc_container.hpp>
 
#define pb push_back
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define sz(v) v.size()
#define x first
#define y second
#define int long long         
#define nl "\n"
 
using namespace std;

typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair <ll, ll> pii;

const int N = (int)3e5 + 7;
const int M = (int)7e6 + 7;
const ll MOD = (ll)1e9 + 7;                    
const int inf = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;

pii dir[] = {{-1, 0}, {1, 0}, {0, 1}, {0, -1}};

int n, q, a[N], p[N][2];

int t[4*N][2];

void upd(int v, int tl, int tr, int id, int x) {
	//cout << v << ' ' << tl << ' ' << tr << nl;
	if(tl == tr) {
		t[v][tl & 1] = x;
		return;
	}
	int mid = (tl + tr) >> 1;
	if(id <= mid)
		upd(v*2, tl, mid, id, x);
	else
		upd(v*2+1, mid+1, tr, id, x);
	t[v][0] = (t[v*2][0] ^ t[v*2+1][0]);
	t[v][1] = (t[v*2][1] ^ t[v*2+1][1]);
} 

int get(int v, int tl, int tr, int l, int r, int x) {
	if(l > tr || tl > r)
		return 0ll;
	if(tl >= l && tr <= r)
		return t[v][x];			
	int mid = (tl + tr) >> 1;
	int res = (get(v*2, tl, mid, l, r, x) ^ get(v*2+1, mid+1, tr, l, r, x));
	return res;
}

void solve() {
	cin >> n >> q;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
    	upd(1, 1, n, i, a[i]); 
	}
	while(q--) {
		char c;
		cin >> c;
		int l, r;
		cin >> l >> r;
		if(c == '1')
			upd(1, 1, n, l, r);
		else {
			if(((r - l + 1) & 1) == 0) cout << "0\n";
			else {
				//cout << t[1][1] << ' ' << t[2][1] << ' ' << t[4][1] << ' ' << t[5][1] << ' '; 	
	
				cout << get(1, 1, n, l, r, l & 1) << nl;
			}
		}
	}
	
} 

signed main() {                   
	ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int test = 1;                       
	//cin >> test;
	for(int i = 1; i <= test; i++) {
        //cout << "Case " << i << ":\n";
        solve();
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 3 ms 588 KB Output is correct
12 Correct 4 ms 588 KB Output is correct
13 Correct 3 ms 588 KB Output is correct
14 Correct 3 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 157 ms 11240 KB Output is correct
2 Correct 178 ms 11208 KB Output is correct
3 Correct 170 ms 11204 KB Output is correct
4 Correct 149 ms 11256 KB Output is correct
5 Correct 159 ms 11276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 3 ms 588 KB Output is correct
12 Correct 4 ms 588 KB Output is correct
13 Correct 3 ms 588 KB Output is correct
14 Correct 3 ms 588 KB Output is correct
15 Correct 157 ms 11240 KB Output is correct
16 Correct 178 ms 11208 KB Output is correct
17 Correct 170 ms 11204 KB Output is correct
18 Correct 149 ms 11256 KB Output is correct
19 Correct 159 ms 11276 KB Output is correct
20 Correct 148 ms 10576 KB Output is correct
21 Correct 156 ms 10668 KB Output is correct
22 Correct 172 ms 10628 KB Output is correct
23 Correct 137 ms 11140 KB Output is correct
24 Correct 156 ms 11212 KB Output is correct