CSES - Shared codeLink to this code: https://cses.fi/paste/6eaed65683ac330d5d4a88/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>order_set;
typedef pair<int, int>pr;
#define all(i) i.begin() , i.end()
#define ft first
#define sn second
#define pb push_back
#define en "\n"
#define dbg cout<<"rony\n"
#define MAXN 200010
#define inf 1e6+5
const ll mod = 1e9 + 7;
int n;
int a[MAXN];
struct segment_tree
{
struct NODE {
int st , EN, value;// start , end
void init(int L, int R) {
st = L, EN = R;
if (L == R) value = a[L];
}
} g[3 * MAXN];
void fill_CN(NODE &CN, NODE &LN, NODE &RN) // fill_current_node
{
CN.value = LN.value ^ RN.value;
}
void build(int CN, int L, int R)
{
g[CN].init(L, R);
if (L == R ) return;
int mid = (L + R) >> 1;
int LN = CN << 1;
build(LN, L, mid);
build(LN | 1, mid + 1, R);
fill_CN (g[CN], g[LN] , g[LN | 1]);
}
int query(int CN, int L, int R)
{
int x = g[CN].st;
int y = g[CN].EN;
if (y < L || x > R) return 0;
if (L <= x && R >= y ) return g[CN].value;
int LN = CN << 1;
int ans = query(LN, L, R);
ans ^= query(LN | 1, L, R);
return ans;
}
} s_tree;
void solve()
{
int q;
cin >> n >> q;
for (int i = 1; i <= n; i++) cin >> a[i];
s_tree.build(1, 1, n);
while (q--)
{
int x, y;
cin >> x >> y;
cout << s_tree.query(1, x, y) << en;
}
}
int main()
{
IOS;
ll t;
t = 1;
// cin >> t;
int c = 0;
while ( t-- )
{
// cout<<"Case "<<++c<<": ";
solve();
}
return 0;
}