Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.68 KB | None | 0 0
  1.  
  2. //#include <bits/stdc++.h>
  3. #include <string>
  4. #include <stack>
  5. #include <queue>
  6. #include <cstdio>
  7. #include <cmath>
  8. #include <iostream>
  9.  
  10.  
  11. #define vpii vector< pair<int,int> >
  12. #define vi vector<int>
  13.  
  14. #define for0(i,a) for(int i=0;i<a;i++)
  15. #define pii pair <int,int>
  16. #define pll pair <long long,long long>
  17. #define sc scanf
  18. #define pf printf
  19. #define Pi 2*acos(0.0)
  20. #define ms(a,b) memset(a, b, sizeof(a))
  21. #define pb(a) push_back(a)
  22. #define MP make_pair
  23. #define db double
  24. #define ll long long
  25. #define ull unsigned long long
  26. #define f first
  27. #define s second
  28. #define sqr(x) (x)*(x)
  29. #define VI vector <int>
  30. #define DBG pf("Hi\n")
  31. #define MOD 1000000007
  32. #define SZ(a) (int)a.size()
  33. #define sf(a) scanf("%d",&a)
  34. #define sfl(a) scanf("%lld",&a)
  35. #define sff(a,b) scanf("%d %d",&a,&b)
  36. #define sffl(a,b) scanf("%lld %lld",&a,&b)
  37. #define sfff(a,b,c) scanf("%d %d %d",&a,&b,&c)
  38. #define sfffl(a,b,c) scanf("%lld %lld %lld",&a,&b,&c)
  39. #define loop(i,n) for(int i=0;i<n;i++)
  40. #define loop1(i,n) for(int i=1;i<=n;i++)
  41. #define REP(i,a,b) for(int i=a;i<b;i++)
  42. #define RREP(i,a,b) for(int i=a;i>=b;i--)
  43. #define intlim 2147483648
  44. #define ull unsigned long long
  45. #define gcd(a, b) __gcd(a, b)
  46. #define lcm(a, b) ((a)*((b)/gcd(a,b)))
  47. #define mk(x1,y1) make_pair(x1, y1)
  48. #define maxl 10000
  49. #define psz 20
  50. #define Fin freopen("input.txt","r",stdin)
  51. #define Fout freopen("output.txt","w",stdout)
  52.  
  53.  
  54. /*----------------------Graph Moves----------------*/
  55. const int fx[]={+1,-1,+0,+0};
  56. const int fy[]={+0,+0,+1,-1};
  57. //const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1}; // Kings Move
  58. //const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1}; // Kings Move
  59. //const int fx[]={-2, -2, -1, -1, 1, 1, 2, 2}; // Knights Move
  60. //const int fy[]={-1, 1, -2, 2, -2, 2, -1, 1}; // Knights Move
  61. /*------------------------------------------------*/
  62.  
  63. /*-----------------------Bitmask------------------*/
  64. //int Set(int N,int pos){return N=N | (1<<pos);}
  65. //int reset(int N,int pos){return N= N & ~(1<<pos);}
  66. //bool check(int N,int pos){return (bool)(N & (1<<pos));}
  67. //freopen("in.txt","r",stdin);
  68. //freopen("out.txt","w",stdout);
  69. //ios_base::sync_with_stdio(false);
  70. //cin.tie(NULL);
  71.  
  72. using namespace std;
  73.  
  74. int main(){
  75.  
  76. //Fin;
  77. // Fout;
  78. int t, cas = 1;
  79. scanf("%d",&t);
  80.  
  81. while(t--){
  82. //cout << "R " << t <<endl;
  83. int n;
  84. scanf("%d",&n);
  85. // cout<<"E "<< n << endl;
  86. ll a[n + 3], a1[n + 3];
  87.  
  88. for(int i = 0; i < n; i++){
  89. scanf("%lld",&a[i]);
  90. //cout<<"E "<< a[i] << endl;
  91. a1[i] = a[i];
  92. }
  93. for(int i = 1; i < n; i++){
  94. a[i] = a[i] ^ a[i - 1];
  95. }
  96. int q;
  97.  
  98. printf("Case %d:\n", cas++);
  99.  
  100. scanf("%d",&q);
  101.  
  102. while(q--){
  103.  
  104. int l, r;
  105. scanf("%d%d",&l, &r);
  106. if( l == r){
  107. printf("%lld\n", a1[l]);
  108. continue;
  109. }
  110.  
  111. int range = ( r - l) + 1;
  112. ll now = 0;
  113. if(range % 2 == 0){
  114. if(l > 0){
  115. now = a[r] ^ a[l - 1];
  116. }
  117. else now = a[r];
  118.  
  119. printf("%lld\n", now);
  120. }
  121. else{
  122. now = a1[l] ^ a1[r];
  123. printf("%lld\n", now);
  124. }
  125. }
  126. }
  127. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement