Facebook
From Md. Rasel, 1 Year ago, written in C++.
Embed
Download Paste or View Raw
Hits: 124
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define endl '\n'
  4. typedef long long LL;
  5.  
  6. const int N = 1e6 + 10;
  7.  
  8. LL n, q, arr[N], pre_xor[N];
  9.  
  10. int main()
  11. {
  12.     ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  13.  
  14.     cin>>n;
  15.     for(int i=1; i<=n; i++)
  16.     {
  17.         cin>>arr[i];
  18.         pre_xor[i] = pre_xor[i-1] ^ arr[i];
  19.     }
  20.     cin>>q;
  21.     while(q--)
  22.     {
  23.         LL l, r;
  24.         cin>>l>>r;
  25.         l = l % (LL)(n+1);
  26.         r = r % (LL)(n+1);
  27.         if(l == 0 and r == 0)
  28.         {
  29.             cout<<pre_xor[n]<<endl;
  30.         }
  31.         else if(l == 0)
  32.         {
  33.             LL cur_xor = pre_xor[r] ^ pre_xor[n];
  34.             cout<<cur_xor<<endl;
  35.         }
  36.         else if(r == 0)
  37.         {
  38.             LL cur_xor = pre_xor[l-1];
  39.             cout<<cur_xor<<endl;
  40.         }
  41.         else if(l <= r)
  42.         {
  43.             LL cur_xor = pre_xor[r] ^ pre_xor[l-1];
  44.             cout<<cur_xor<<endl;
  45.         }
  46.         else
  47.         {
  48.             LL baki_right = pre_xor[l-1];
  49.             LL baki_left = pre_xor[r];
  50.             LL cur_xor = baki_left ^ baki_right;
  51.             cout<<cur_xor<<endl;
  52.         }
  53.     }
  54. }
  55.  
  56. /*
  57.  
  58. 5
  59. 3 3 4 3 2
  60. 1
  61. 6 7
  62.  
  63. */
  64.