Submission #634360

# Submission time Handle Problem Language Result Execution time Memory
634360 2022-08-24T09:37:07 Z smartmonky XORanges (eJOI19_xoranges) C++14
100 / 100
523 ms 15820 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <set>
#include <map>
 
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define int ll
using namespace std;
const int N=3e5;
ll t[2][N*4],a[N],n;
void build(int v=1,int tl=1,int tr=n){
	if(tl==tr){
	//	cout << (tl&1) <<" " <<v  <<" "<< a[tl]<<endl;
		t[(tl & 1)][v]=a[tl];
	}else{
		int mid=(tl+tr) >> 1;
		build(v*2,tl,mid);
		build(v*2+1,mid+1,tr);
	t[1][v]=(t[1][v*2]^t[1][v*2+1]);
	t[0][v]=(t[0][v*2]^t[0][v*2+1]);
	}
}
void upd(int pos,int val,int v=1, int tl=1,int tr=n){
	if(tl==tr){
		t[(tl & 1)][v]=val;
	}else{
		int mid=(tl+tr) >> 1;
		if(pos<=mid)
			upd(pos,val,v*2,tl,mid);
		else
			upd(pos,val,v*2+1,mid+1,tr);
	t[1][v]=(t[1][v*2]^t[1][v*2+1]);
	t[0][v]=(t[0][v*2]^t[0][v*2+1]);
	}
}
int get(int l,int r,int v=1,int tl=1,int tr=n){
	if (l > tr || tl > r)
        return 0;
        
    if (l <= tl && tr <= r)
        return t[l & 1][v];
        
    int tm = (tl + tr) >> 1;
    
    return get(l, r, v + v, tl, tm) ^ get(l, r, v + v + 1, tm + 1, tr);
}
main(){
    int q;
    cin >> n>>q;
    for(int i=1;i<=n;i++)
		cin >>a[i];
	build();

	while(q--){
		int type,x,y;
		cin >>type >>x >>y;
		if(type==1)
			upd(x,y);
		else{
			if((y-x+1)%2==0)
				cout<<0<<endl;
			else
				cout <<get(x,y)<<endl;
		}
	}
}

Compilation message

xoranges.cpp:53:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   53 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 2 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 304 KB Output is correct
11 Correct 9 ms 596 KB Output is correct
12 Correct 10 ms 596 KB Output is correct
13 Correct 12 ms 640 KB Output is correct
14 Correct 12 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 511 ms 11256 KB Output is correct
2 Correct 498 ms 11296 KB Output is correct
3 Correct 523 ms 11168 KB Output is correct
4 Correct 461 ms 11212 KB Output is correct
5 Correct 481 ms 11256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 304 KB Output is correct
11 Correct 9 ms 596 KB Output is correct
12 Correct 10 ms 596 KB Output is correct
13 Correct 12 ms 640 KB Output is correct
14 Correct 12 ms 632 KB Output is correct
15 Correct 511 ms 11256 KB Output is correct
16 Correct 498 ms 11296 KB Output is correct
17 Correct 523 ms 11168 KB Output is correct
18 Correct 461 ms 11212 KB Output is correct
19 Correct 481 ms 11256 KB Output is correct
20 Correct 394 ms 10928 KB Output is correct
21 Correct 433 ms 15776 KB Output is correct
22 Correct 394 ms 15820 KB Output is correct
23 Correct 484 ms 15728 KB Output is correct
24 Correct 488 ms 15708 KB Output is correct