Submission #468590

# Submission time Handle Problem Language Result Execution time Memory
468590 2021-08-28T23:09:14 Z _Body XORanges (eJOI19_xoranges) C++14
100 / 100
648 ms 29556 KB
#include <bits/stdc++.h>
using namespace std;
/*#pragma GCC optimize("-Ofast")
#pragma GCC optimize("trapv")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-funroll-loops")*/
 #define int long long
 int tree[(int)(2e5+1)*4],arr[(int)2e5+1];
 int n;
 void build(int l,int r,int v)
{
	if(l==r)
	{
		tree[v]=arr[l];
	}
	else
	{
		int mid=(l+r)/2;
		build(l,mid,v*2+1);
		build(mid+1,r,v*2+2);
		tree[v]=tree[v*2+1]^tree[v*2+2];
	}
}
 int get(int l,int r,int v,int lq,int rq)
{
	if(r<lq||l>rq)
		return 0;
	if(l>=lq&&r<=rq)
		return tree[v];
	int mid=(l+r)/2;
	return get(l,mid,v*2+1,lq,rq)^get(mid+1,r,v*2+2,lq,rq);
}
 void update(int l,int r,int idx,int val,int v)
{
	if(l==r)
	{
		tree[v]=val;
	}
	else
	{
		int mid=(l+r)/2;
		if(idx<=mid)
			update(l,mid,idx,val,v*2+1);
		else update(mid+1,r,idx,val,v*2+2);
		tree[v]=tree[v*2+1]^tree[v*2+2];
	}
}
int32_t main() {
	  ios_base::sync_with_stdio(0);
  cin.tie(0);
cin>>n;
 int q;
 cin>>q;

								    	 for(int i=0;i<n*4;i++)
                                            tree[i]=0;
								    	for(int i=0;i<n;i++)
								    		cin>>arr[i];
								    	int idx=0;
								    	map<int,int>map;

								    	int arr2[n];
								    	for(int i=0;i<n;i+=2){
								    	map[i]=idx;
								    		arr2[idx++]=arr[i];
								    	}
								    	for(int i=1;i<n;i+=2){
								    		map[i]=idx;
								    		arr2[idx++]=arr[i];
								    	}
								    	copy(arr2, arr2+n, arr);
								    	build(0,n-1,0);
								    	vector<int>ans;
								    	for(int i=0;i<q;i++)
								    	{
								    	    int t;
								    		cin>>t;
								    		if(t==1)
								    		{
								    			cin>>idx;
								    			idx--;
								    			 int val;
								    			 cin>>val;
								    			idx=map[idx];

								    			update(0,n-1,idx,val,0);
								    		}
								    		else
								    		{
								    		    int l,r;
								    		    cin>>l>>r;
								    		    l--,r--;
								    			if((r-l+1)%2==0)
								    			{
								    				ans.push_back(0);
								    				continue ;
								    			}
								    			l=map[l];
								    			r=map[r];
								    			ans.push_back(get(0,n-1,0,l,r));
								    		}
								    	}
								    	for(int i=0;i<ans.size();i++)
                                            cout<<ans[i]<<endl;
	return 0;
}

Compilation message

xoranges.cpp: In function 'int32_t main()':
xoranges.cpp:104:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  104 |              for(int i=0;i<ans.size();i++)
      |                          ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 9 ms 844 KB Output is correct
12 Correct 9 ms 936 KB Output is correct
13 Correct 11 ms 972 KB Output is correct
14 Correct 12 ms 1004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 648 ms 29556 KB Output is correct
2 Correct 642 ms 25468 KB Output is correct
3 Correct 625 ms 25504 KB Output is correct
4 Correct 515 ms 25484 KB Output is correct
5 Correct 521 ms 25640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 9 ms 844 KB Output is correct
12 Correct 9 ms 936 KB Output is correct
13 Correct 11 ms 972 KB Output is correct
14 Correct 12 ms 1004 KB Output is correct
15 Correct 648 ms 29556 KB Output is correct
16 Correct 642 ms 25468 KB Output is correct
17 Correct 625 ms 25504 KB Output is correct
18 Correct 515 ms 25484 KB Output is correct
19 Correct 521 ms 25640 KB Output is correct
20 Correct 476 ms 24276 KB Output is correct
21 Correct 470 ms 24116 KB Output is correct
22 Correct 480 ms 24264 KB Output is correct
23 Correct 502 ms 25316 KB Output is correct
24 Correct 501 ms 25256 KB Output is correct