#include <bits/stdc++.h>
using namespace std;
#define fii(i,a,b) for(int i = a; i <= b; i++)
#define fid(i,a,b) for(int i = a; i >= b; i--)
#define ll long long
#define fi first
#define se second
#define pii pair< int, int >
#define pll pair< long long , long long >
#define sz(x) int(x.size())
#define faster ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define maxn 1000005
#define all(a) a.begin(), a.end()
#define ins insert
#define pb push_back
#define Base 13
// #define int long long
#define MOD 1000000007
#define endl '\n'
#define fill(a,n) memset(a, n, sizeof(a));
#define re return
#define name "file"
ll a[maxn];
ll Tc[4 * maxn], Tl[maxn * 4];
void build(int id, int l, int r)
{
if(l == r)
{
if(l % 2 == 0)
{
Tc[id] = a[l];
Tl[id] = 0;
}
else
{
Tl[id] = a[l];
Tc[id] = 0;
}
re;
}
int mid = (l + r) / 2;
build(id * 2, l, mid);
build(id * 2 + 1, mid + 1, r);
Tc[id] = Tc[id * 2] ^ Tc[id * 2 + 1];
Tl[id] = Tl[id * 2] ^ Tl[id * 2 + 1];
}
void update(int id, int l, int r, int pos, int w)
{
if(l == r)
{
if(l % 2 == 0)
{
Tc[id] = w;
}
else Tl[id] = w;
re;
}
int mid = (l + r) / 2;
if(mid >= pos) update(id * 2, l, mid, pos, w);
else update(id * 2 + 1, mid + 1, r, pos, w);
Tc[id] = Tc[id * 2] ^ Tc[id * 2 + 1];
Tl[id] = Tl[id * 2] ^ Tl[id * 2 + 1];
}
ll get_odd(int id, int l, int r, int u, int v)
{
if(l > v || r < u) re 0;
if(l >= u && r <= v)
{
return Tl[id];
}
int mid = (l + r) / 2;
return get_odd(id * 2, l, mid, u, v) ^ get_odd(id * 2 + 1, mid + 1, r, u, v);
}
ll get_even(int id, int l, int r, int u, int v)
{
if(l > v || r < u) re 0;
if(l >= u && r <= v) re Tc[id];
int mid = (l + r) / 2;
return get_even(id * 2, l, mid, u, v) ^ get_even(id * 2 + 1, mid + 1, r, u, v);
}
int main(){
if(fopen(name".INP","r")){
freopen(name".INP", "r", stdin);
freopen(name".OUT", "w", stdout);
}
faster
int n, q;
cin >> n >> q;
fii(i, 1, n)
{
cin >> a[i];
}
build(1, 1, n);
while(q--)
{
int t, u, v;
cin >> t >> u >> v;
if(t == 1)
{
update(1, 1, n, u, v);
}
else
{
if((v - u + 1) % 2 == 0) cout << 0 << '\n';
else
{
if(u % 2 == 0) cout << get_even(1, 1, n, u, v);
else cout << get_odd(1, 1, n, u, v);
cout << endl;
}
}
}
}
Compilation message
xoranges.cpp: In function 'int main()':
xoranges.cpp:87:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
87 | freopen(name".INP", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
xoranges.cpp:88:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
88 | freopen(name".OUT", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
3 ms |
4700 KB |
Output is correct |
12 |
Correct |
3 ms |
4832 KB |
Output is correct |
13 |
Correct |
3 ms |
4696 KB |
Output is correct |
14 |
Correct |
3 ms |
4700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
106 ms |
20988 KB |
Output is correct |
2 |
Correct |
120 ms |
20892 KB |
Output is correct |
3 |
Correct |
99 ms |
20852 KB |
Output is correct |
4 |
Correct |
89 ms |
20564 KB |
Output is correct |
5 |
Correct |
90 ms |
20692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
3 ms |
4700 KB |
Output is correct |
12 |
Correct |
3 ms |
4832 KB |
Output is correct |
13 |
Correct |
3 ms |
4696 KB |
Output is correct |
14 |
Correct |
3 ms |
4700 KB |
Output is correct |
15 |
Correct |
106 ms |
20988 KB |
Output is correct |
16 |
Correct |
120 ms |
20892 KB |
Output is correct |
17 |
Correct |
99 ms |
20852 KB |
Output is correct |
18 |
Correct |
89 ms |
20564 KB |
Output is correct |
19 |
Correct |
90 ms |
20692 KB |
Output is correct |
20 |
Correct |
91 ms |
20580 KB |
Output is correct |
21 |
Correct |
94 ms |
20568 KB |
Output is correct |
22 |
Correct |
95 ms |
20640 KB |
Output is correct |
23 |
Correct |
97 ms |
20500 KB |
Output is correct |
24 |
Correct |
87 ms |
20560 KB |
Output is correct |