Submission #569922

#TimeUsernameProblemLanguageResultExecution timeMemory
569922jmyszka2007XORanges (eJOI19_xoranges)C++17
100 / 100
162 ms7952 KiB
#include <bits/stdc++.h>
using namespace std;
constexpr int base = (1 << 18);
int d1[2 * base];
int d2[2 * base];
void upd1(int v, int x) {
	v += base;
	d1[v] = x;
	v >>= 1;
	while(v > 0) {
		d1[v] = d1[2 * v] ^ d1[2 * v + 1];
		v >>= 1;
	}
}
int que1(int l, int r) {
	l += base;
	r += base;
	int ans = 0;
	while(l <= r) {
		if(l & 1) {
			ans ^= d1[l];
		}
		if(!(r & 1)) {
			ans ^= d1[r];
		}
		l++;
		l >>= 1;
		r--;
		r >>= 1;
	}
	return ans;
}
void upd2(int v, int x) {
	v += base;
	d2[v] = x;
	v >>= 1;
	while(v > 0) {
		d2[v] = d2[2 * v] ^ d2[2 * v + 1];
		v >>= 1;
	}
}
int que2(int l, int r) {
	l += base;
	r += base;
	int ans = 0;
	while(l <= r) {
		if(l & 1) {
			ans ^= d2[l];
		}
		if(!(r & 1)) {
			ans ^= d2[r];
		}
		l++;
		l >>= 1;
		r--;
		r >>= 1;
	}
	return ans;
}	 
int main() {
	int n, t;
	scanf("%d%d", &n, &t);
	for(int i = 1; i <= n; i++) {
		int x;
		scanf("%d", &x);
		if(i & 1) {
			upd1(i / 2 + 1, x);
		}
		else {
			upd2(i / 2, x);
		}
	}
	while(t--) {
		int tp;
		scanf("%d", &tp);
		if(tp == 1) {
			int v, x;
			scanf("%d%d", &v, &x);
			if(v & 1) {
				upd1(v / 2 + 1, x);
			}
			else {
				upd2(v / 2, x);
			}
		}
		else {
			int l, r;
			scanf("%d%d", &l, &r);
			if((l & 1) != (r & 1)) {
				printf("%d\n", 0);
			}
			else {
				if(l & 1) {
					printf("%d\n", que1(l / 2 + 1, r / 2 + 1));
				}
				else {
					printf("%d\n", que2(l / 2, r / 2));
				}
			}
		}
	}
}

Compilation message (stderr)

xoranges.cpp: In function 'int main()':
xoranges.cpp:62:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |  scanf("%d%d", &n, &t);
      |  ~~~~~^~~~~~~~~~~~~~~~
xoranges.cpp:65:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |   scanf("%d", &x);
      |   ~~~~~^~~~~~~~~~
xoranges.cpp:75:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |   scanf("%d", &tp);
      |   ~~~~~^~~~~~~~~~~
xoranges.cpp:78:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |    scanf("%d%d", &v, &x);
      |    ~~~~~^~~~~~~~~~~~~~~~
xoranges.cpp:88:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |    scanf("%d%d", &l, &r);
      |    ~~~~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...