답안 #971939

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
971939 2024-04-29T14:11:32 Z Sunbae XORanges (eJOI19_xoranges) C++17
0 / 100
93 ms 4652 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 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 93 ms 4652 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2396 KB Output isn't correct
2 Halted 0 ms 0 KB -