Submission #1080104

# Submission time Handle Problem Language Result Execution time Memory
1080104 2024-08-29T07:09:14 Z timoni XORanges (eJOI19_xoranges) C++17
55 / 100
82 ms 10068 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 = 3e5 + 5;
int mod = 1e9 + 7;
const int INF = 1e18;
int n,q,a[N],t[3][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[0][v] = t[0][v * 2] ^ t[0][v * 2 + 1];
	t[1][v] = t[1][v * 2] ^ t[1][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:52:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   52 |  int tm = tl + tr >> 1;
      |           ~~~^~~~
# Verdict Execution time Memory 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 4440 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory 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 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory 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 4440 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 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 3 ms 4696 KB Output is correct
12 Correct 2 ms 4700 KB Output is correct
13 Correct 2 ms 4696 KB Output is correct
14 Correct 2 ms 4560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 82 ms 10068 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 4440 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 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 3 ms 4696 KB Output is correct
12 Correct 2 ms 4700 KB Output is correct
13 Correct 2 ms 4696 KB Output is correct
14 Correct 2 ms 4560 KB Output is correct
15 Incorrect 82 ms 10068 KB Output isn't correct
16 Halted 0 ms 0 KB -