Advertisement
Guest User

Untitled

a guest
Nov 3rd, 2018
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. typedef unsigned long long ull;
  5. const int inf_int=1e9+100;
  6. const ll inf_ll=1e16;
  7. typedef pair<int,int> pii;
  8. typedef pair<ll,ll> pll;
  9. typedef long double dbl;
  10. #define pb push_back
  11. const double pi=3.1415926535898;
  12. #define dout if(debug) cout
  13. #define fi first
  14. #define se second
  15. #define sp setprecision
  16. #define sz(a) (int(a.size()))
  17. #define all(a) a.begin(),a.end()
  18. bool debug = 0;
  19. const int MAXN = 1<<18;
  20. const int LOG = 20;
  21. const ll mod =998244353;
  22.  
  23. const int MX_LEVEL = 1<<9;
  24. int n,q;
  25.  
  26. int a[MAXN];
  27. int ans[MX_LEVEL][MAXN];
  28. int STAR_BIT[MAXN];
  29.  
  30. int get(int i,int level){
  31. if(level < MX_LEVEL){
  32. return ans[level][i];
  33. }
  34. int BIT = STAR_BIT[level];
  35. int res = get(i, level ^ (1<<BIT));
  36. int to = i + (1<<BIT);
  37. if( to < n){
  38. res = res ^ get(to, level ^ (1 << BIT));
  39. }
  40. return res;
  41. }
  42.  
  43. void solve(){
  44. cin >> n;
  45. cin >> q;
  46. for(int i=0;i<n;++i){
  47. cin >> a[i];
  48. ans[0][i] = a[i];
  49. }
  50.  
  51. for(int i=0;i<MAXN;++i){
  52. for(int j = 0;j < 20;++j){
  53. if(i&(1<<j)){
  54. STAR_BIT[i] = j;
  55. }
  56. }
  57. }
  58.  
  59. for(int level = 1;level < (MX_LEVEL); ++level){
  60. int BIT = STAR_BIT[level];
  61. int next_level = level ^ (1<<BIT);
  62. int add = (1<<BIT);
  63. for(int i=0;i<n;++i){
  64. ans[level][i] = ans[next_level][i];
  65. int to = i + add;
  66. if(to<n){
  67. ans[level][i]^=ans[next_level][to];
  68. }
  69. }
  70. }
  71.  
  72.  
  73.  
  74. while(q--){
  75. int k,x;
  76. cin >> k >> x;
  77. k = k % MAXN;
  78. cout << get(x-1,k)<<"\n";
  79. }
  80.  
  81. }
  82.  
  83. signed main()
  84. {
  85. #ifdef zxc
  86. debug = 1;
  87. freopen("input.txt","r",stdin);
  88. //freopen("output1.txt","w",stdout);
  89. #else
  90. #endif //zxc
  91. ios_base::sync_with_stdio(0);
  92. cin.tie(0); cout.tie(0);
  93. cout.setf(ios::fixed);
  94. cout.precision(20);
  95. int t = 1;
  96. while(t--)
  97. solve();
  98. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement