This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |