답안 #1080110

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1080110 2024-08-29T07:11:31 Z timoni XORanges (eJOI19_xoranges) C++17
100 / 100
91 ms 20992 KB
//don't copy pls)
/*TAAK ZDES NADO RECURSIU PISAT*/

//I'm not in the danger i am the DANGER
#include "bits/stdc++.h"
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define pb push_back
#define int long long
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define pii pair<int,int>
#define sigma signed
using namespace std;
using namespace __gnu_pbds;
const int N = 1e6 + 5;
int mod = 1e9 + 7;
const int INF = 1e18;
int n,q,a[N],t[2][N];
void build(int v = 1 , int tl = 1 , int tr = n){
	if(tl == tr){
		if(tl % 2){
			t[1][v] = a[tl];
		}
		else{
			t[0][v] = a[tl];
		}
		return;
	}
	int tm = tl + tr >> 1;
	build(v * 2 , tl , tm);
	build(v * 2 + 1 , tm + 1 , tr);
	t[0][v] = t[0][v * 2] ^ t[0][v * 2 + 1];
	t[1][v] = t[1][v * 2] ^ t[1][v * 2 + 1];
}
void upd(int pos , int x , int v = 1 , int tl = 1 , int tr = n){
	if(tl > pos || tr < pos) return;
	if(tl == pos && tr == pos){
		t[pos % 2][v] = x;
		return;
	}
	int tm = tl + tr >> 1;
	upd(pos , x , v * 2 , tl , tm);
	upd(pos , x , v * 2 + 1 , tm + 1 , tr);
	t[pos % 2][v] = t[pos % 2][v * 2] ^ t[pos % 2][v * 2 + 1];
}
int get(int id , int l , int r , int v = 1 , int tl = 1 , int tr = n){
	if(tl > r || tr < l) return 0;
	if(tl >= l && tr <= r) return t[id][v];
	int tm = tl + tr >> 1;
	return get(id , l , r , v * 2 , tl , tm) ^ get(id , l , r , v * 2 + 1 , tm + 1 , tr);
}
void Gold(){
	cin >> n >> q;
	for(int i = 1 ; i <= n ; i++){
		cin >> a[i];
	}
	build();
	while(q--){
		int tp;
		cin >> tp;
		if(tp == 1){
			int x,y;
			cin >> x >> y;
			upd(x , y);
		}
		else{
			int l,r;
			cin >> l >> r;
			if((r - l + 1) % 2 == 0){
				cout << 0 << '\n';
				continue;
			}
			cout << get((l % 2) , l , r) << '\n';
			continue;
			// int x = 0;
			// map <int,int> mp;
			// for(int i = l ; i <= r ; i++){
				// ans[i] = 0;
			// }
			// for(int i = 1 ; i <= n ; i++){
				// p[i] = p[i - 1] ^ a[i];
			// }
			// for(int j = 1 ; j <= r - l + 1 ; j++){
				// for(int i = l + j - 1 ; i <= r ; i++){
					// // x ^= get(1 , i - j + 1 , i) ^ get(0 , i - j + 1 , i);
					// // x ^= (p[i] ^ p[i - j]);
					// for(int k = i - j + 1 ; k <= i ; k++){
						// mp[a[k]]++;
						// x ^= a[k];
						// // cout << x << ' ';
					// }
					// // cout << '\n';
				// }
			// }
			// // cout << '\n';
			// for(auto it : mp){
				// cout << it.F << ' ' << it.S << '\n';
			// }
			// cout << x << '\n';
		}
	}
}
sigma main(){
	//freopen("txt.in","r",stdin);
	//freopen("txt.out","w",stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	srand(time(0));
	int TT = 1;
	// cin >> TT;
	for(int i = 1 ; i <= TT ; i++){
		//cout << "Case " << i << ": ";
		Gold();
	}
}

Compilation message

xoranges.cpp: In function 'void build(long long int, long long int, long long int)':
xoranges.cpp:31:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   31 |  int tm = tl + tr >> 1;
      |           ~~~^~~~
xoranges.cpp: In function 'void upd(long long int, long long int, long long int, long long int, long long int)':
xoranges.cpp:43:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   43 |  int tm = tl + tr >> 1;
      |           ~~~^~~~
xoranges.cpp: In function 'long long int get(long long int, long long int, long long int, long long int, long long int, long long int)':
xoranges.cpp:51:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |  int tm = tl + tr >> 1;
      |           ~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4572 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4572 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 2 ms 4700 KB Output is correct
12 Correct 3 ms 4700 KB Output is correct
13 Correct 2 ms 4668 KB Output is correct
14 Correct 2 ms 4668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 18696 KB Output is correct
2 Correct 83 ms 20820 KB Output is correct
3 Correct 84 ms 20992 KB Output is correct
4 Correct 78 ms 20816 KB Output is correct
5 Correct 79 ms 20672 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4572 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 2 ms 4700 KB Output is correct
12 Correct 3 ms 4700 KB Output is correct
13 Correct 2 ms 4668 KB Output is correct
14 Correct 2 ms 4668 KB Output is correct
15 Correct 89 ms 18696 KB Output is correct
16 Correct 83 ms 20820 KB Output is correct
17 Correct 84 ms 20992 KB Output is correct
18 Correct 78 ms 20816 KB Output is correct
19 Correct 79 ms 20672 KB Output is correct
20 Correct 87 ms 20564 KB Output is correct
21 Correct 91 ms 20560 KB Output is correct
22 Correct 83 ms 20560 KB Output is correct
23 Correct 81 ms 20564 KB Output is correct
24 Correct 76 ms 20676 KB Output is correct