Submission #336649

# Submission time Handle Problem Language Result Execution time Memory
336649 2020-12-16T08:38:25 Z Nursik XORanges (eJOI19_xoranges) C++14
100 / 100
862 ms 11628 KB
#include <bits/stdc++.h>
          
#define fi first
#define se second
#define pp pop_back
#define ll long long
#define pb push_back
#define ld long double
#define debug cout << "OK\n";
#define all(x) x.begin(), x.end() 
 
using namespace std;        
 
const int N = 1e6 + 200;
const int mod = 1e9 + 7;
const int mod2 = 998244353;
 
 
 
/*
Rucode: jaqVYNrpMj
JUDGE_ID: 295965SY
*/
void data()
{
	#ifdef NURS
        freopen("main.in", "r", stdin);
        freopen("main.out", "w", stdout);
    #endif	
}
void speed_force()
{
	ios_base::sync_with_stdio(0),
	cin.tie(0),cout.tie(0);
} 
 
int n, q;
int a[N];
struct seg_tree
{
	int t[N * 4];
	void upd(int pos, int val, int v = 1, int tl = 1, int tr = n)
	{
		if (tl == tr)
		{
			t[v] = val; return;
		}
		int tm = (tl + tr) / 2;
		if (pos <= tm)
			upd(pos, val, v * 2, tl, tm);
		else
			upd(pos, val, v * 2 + 1, tm + 1, tr);
		t[v] = (t[v + v] ^ t[v + v + 1]);
	}
	int get(int l, int r, int v = 1, int tl = 1, int tr = n)
	{
		if (l <= tl && tr <= r)
			return t[v];
		if (l > tr || r < tl)
			return 0;
		int tm = (tl + tr) / 2;
		return (get(l, r, v * 2, tl, tm) ^ (get(l, r, v * 2 + 1, tm + 1, tr)));
	}
} tree[4];
main()            
{
	data();
	cin >> n >> q;
	for (int i = 1; i <= n; i++)
	{
		tree[0].upd(i, 0);
		tree[1].upd(i, 0);
	}
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		if (i & 1)
			tree[1].upd(i, a[i]);
		else
			tree[0].upd(i, a[i]);	
	}    
	for (int i = 1; i <= q; i++)
	{
		int type;
		cin >> type;
		if (type == 2)
		{
			int l, r;
			cin >> l >> r;
			if ((r - l + 1) % 2 == 0)
			{
				cout << 0;
			}
			else
			{
				if (l % 2)
				{         
					cout << tree[1].get(l, r);
				}
				else
				{
					cout << tree[0].get(l, r); 
				}
			}
			cout << '\n';
		}
		else
		{
			int pos, x;
			cin >> pos >> x;
			if (pos & 1)
				tree[1].upd(pos, x);
			else
				tree[0].upd(pos, x);
		}
	}	
} 
/*
n = 6
(1, 2, 3, 4, 5, 6, 7)
 1  0  1  0  1  0  1
*/

Compilation message

xoranges.cpp:65:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   65 | main()
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 364 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 3 ms 364 KB Output is correct
4 Correct 2 ms 364 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 3 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 17 ms 620 KB Output is correct
12 Correct 14 ms 620 KB Output is correct
13 Correct 19 ms 620 KB Output is correct
14 Correct 19 ms 640 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 862 ms 11500 KB Output is correct
2 Correct 854 ms 11500 KB Output is correct
3 Correct 851 ms 11628 KB Output is correct
4 Correct 817 ms 11116 KB Output is correct
5 Correct 805 ms 10988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 3 ms 364 KB Output is correct
7 Correct 2 ms 364 KB Output is correct
8 Correct 3 ms 364 KB Output is correct
9 Correct 2 ms 364 KB Output is correct
10 Correct 2 ms 384 KB Output is correct
11 Correct 17 ms 620 KB Output is correct
12 Correct 14 ms 620 KB Output is correct
13 Correct 19 ms 620 KB Output is correct
14 Correct 19 ms 640 KB Output is correct
15 Correct 862 ms 11500 KB Output is correct
16 Correct 854 ms 11500 KB Output is correct
17 Correct 851 ms 11628 KB Output is correct
18 Correct 817 ms 11116 KB Output is correct
19 Correct 805 ms 10988 KB Output is correct
20 Correct 632 ms 11108 KB Output is correct
21 Correct 623 ms 11116 KB Output is correct
22 Correct 625 ms 11144 KB Output is correct
23 Correct 790 ms 10988 KB Output is correct
24 Correct 798 ms 10988 KB Output is correct