Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define nl "\n"
- #define fi first
- #define se second
- #define pb push_back
- #define ll long long
- #define ull unsigned ll
- #define RV return void
- #define sz(x) int(x.size())
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define fixed(n) fixed << setprecision(n)
- #define cin(v) for (auto&i:v) cin >> i;
- #define cout(v) for (auto&i:v) cout << i << " ";
- #define clr(memo, x) memset(memo, x, sizeof memo)
- #define FastCode ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
- void Zainab(){
- // #ifndef ONLINE_JUDGE
- // freopen("hobz.in", "r", stdin);
- // freopen("longpath.out", "w", stdout);
- // #endif
- }
- void myCode( ){
- ll n ,q;
- cin >> n >> q;
- vector < ll > v(n);
- cin(v);
- // if len of subarray even => take Xor for all element exactly once
- // odd length => 1 (1)
- // 3 (101)
- // 5(10101)
- vector < ll > prefEven(n+1) , prefodd0(n+1) , prefodd1(n+1);
- for(int i =0 ; i < n ; i++){
- prefEven[i] = v[i];
- if(i)
- prefEven[i] ^= prefEven[i-1];
- }
- for(int i =0 ; i < n ; i++){
- if(i % 2 )
- prefodd0[i] = v[i];
- if(i)
- prefodd0[i] ^= prefodd0[i-1];
- }
- for(int i =0 ; i < n ; i++){
- if(i % 2==0)
- prefodd1[i] = v[i];
- if(i)
- prefodd1[i] ^= prefodd1[i-1];
- }
- while(q--){
- ll l , r;
- cin >> l >> r;
- ll len = r-l+1;
- l--; r--;
- if(len % 2 ==0){
- ll tx =0;
- if(l)
- tx = prefEven[l-1];
- cout << (prefEven[r] ^ tx) << nl;
- }
- else{
- if( (l+1) % 2 ){
- ll tx =0;
- if(l)
- tx = prefodd1[l-1];
- cout << (prefodd1[r] ^ tx) << nl;
- }
- else{
- ll tx =0;
- if(l)
- tx = prefodd0[l-1];
- cout << (prefodd0[r] ^ tx) << nl;
- }
- }
- }
- }
- int main(){
- FastCode ;
- // Zainab();
- int testCase=1;
- cin >> testCase ;
- for(int i=1 ; i<= testCase ; i++)
- myCode();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement