답안 #971941

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
971941 2024-04-29T14:13:45 Z Sunbae XORanges (eJOI19_xoranges) C++17
100 / 100
97 ms 4972 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int N = 2e5 + 5;
int a[N], n, q;
ll bit[2][N];
void upd(int x, int i, ll val){
	for(++i; i<N; i+=i&-i) bit[x][i] ^= val;
}
ll qry(int x, int i){
	ll res = 0; for(++i; i; i-=i&-i) res ^= bit[x][i]; return res;
}
ll sum(int x, int l, int r){
	return qry(x, r) ^ qry(x, l-1);
}
signed main(){
	scanf("%d %d", &n, &q);
	for(int i = 0; i<n; ++i) scanf("%d", a+i);
	for(int i = 0; i<n; ++i){
		upd(i&1, i>>1, a[i]);
	}
	while(q--){
		int t; scanf("%d", &t);
		if(t == 1){
			int i, val; scanf("%d %d", &i, &val); --i;
			upd(i&1, i>>1, val ^ a[i]);
			a[i] = val;
		}else if(t == 2){
			int l, r; scanf("%d %d", &l, &r); --l; --r;
			ll T = 0;
			if((r-l+1)&1){
				if(!(l&1)){
					int R = r;
					if(R&1) --R;
					T = sum(0, l>>1, R>>1);
				}else if(l&1){
					int R = r;
					if(!(R&1)) --R;
					T = sum(1, l>>1, R>>1);
				}
			}	
			printf("%lld\n", T);
		}
	}
}

Compilation message

xoranges.cpp: In function 'int main()':
xoranges.cpp:17:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |  scanf("%d %d", &n, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~~
xoranges.cpp:18:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |  for(int i = 0; i<n; ++i) scanf("%d", a+i);
      |                           ~~~~~^~~~~~~~~~~
xoranges.cpp:23:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |   int t; scanf("%d", &t);
      |          ~~~~~^~~~~~~~~~
xoranges.cpp:25:21: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |    int i, val; scanf("%d %d", &i, &val); --i;
      |                ~~~~~^~~~~~~~~~~~~~~~~~~
xoranges.cpp:29:19: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |    int l, r; scanf("%d %d", &l, &r); --l; --r;
      |              ~~~~~^~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 2 ms 2392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 1 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 2 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 3 ms 2392 KB Output is correct
12 Correct 3 ms 2396 KB Output is correct
13 Correct 3 ms 2396 KB Output is correct
14 Correct 3 ms 2396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 91 ms 4972 KB Output is correct
2 Correct 94 ms 4688 KB Output is correct
3 Correct 85 ms 4768 KB Output is correct
4 Correct 83 ms 4736 KB Output is correct
5 Correct 82 ms 4736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 1 ms 2396 KB Output is correct
4 Correct 1 ms 2396 KB Output is correct
5 Correct 2 ms 2392 KB Output is correct
6 Correct 1 ms 2392 KB Output is correct
7 Correct 1 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 3 ms 2392 KB Output is correct
12 Correct 3 ms 2396 KB Output is correct
13 Correct 3 ms 2396 KB Output is correct
14 Correct 3 ms 2396 KB Output is correct
15 Correct 91 ms 4972 KB Output is correct
16 Correct 94 ms 4688 KB Output is correct
17 Correct 85 ms 4768 KB Output is correct
18 Correct 83 ms 4736 KB Output is correct
19 Correct 82 ms 4736 KB Output is correct
20 Correct 81 ms 3920 KB Output is correct
21 Correct 78 ms 4040 KB Output is correct
22 Correct 79 ms 4128 KB Output is correct
23 Correct 91 ms 4692 KB Output is correct
24 Correct 97 ms 4688 KB Output is correct