Advertisement
Guest User

Untitled

a guest
Apr 15th, 2021
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4. #define aditya ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  5. #define MOD 1000000007
  6. #define endl "\n"
  7. #define pb push_back
  8. #define ss second
  9. #define ff first
  10. #define vi vector<int>
  11. #define all(a) a.begin(),a.end()
  12. #define MAXN 1000001
  13. #define BLOCK 500
  14.  
  15.  
  16.  
  17.  
  18. struct query{
  19. int l;
  20. int r;
  21. int k;
  22. int i;
  23. };
  24.  
  25. deque<int>a(MAXN);
  26. query Q[200001];
  27. int ans[200001];
  28. int fre[1000001];
  29. int cnt = 0;
  30.  
  31.  
  32. bool comp(query a , query b){
  33. if(a.l / BLOCK != b.l/BLOCK)
  34. return a.l/BLOCK < b.l/BLOCK;
  35.  
  36. return a.r < b.r;
  37. }
  38.  
  39. void add(int pos,int idx){
  40. int val = a[pos];
  41. int num = __builtin_popcount(val);
  42. if(num==Q[idx].k)cnt++;
  43. fre[cnt]++;
  44. }
  45.  
  46. void remove(int pos,int idx){
  47. int val = a[pos];
  48. int num = __builtin_popcount(val);
  49. if(num==Q[idx].k)cnt--;
  50. fre[cnt]--;
  51. }
  52.  
  53.  
  54. int32_t main(){
  55. int t;
  56. cin>>t;
  57. while(t--){
  58. int n,q;
  59. cin>>n>>q;
  60.  
  61.  
  62.  
  63. for(int i = 0;i<n;i++){
  64. cin>>a[i];
  65. }
  66.  
  67.  
  68.  
  69. int j = 0;
  70. while(q--){
  71. int z;
  72. cin>>z;
  73.  
  74. if(z==1){
  75. int y;
  76. cin>>y;
  77. --y;
  78. int val = a[y];
  79. // cout<<"VAL : "<<val<<endl;
  80. if(val%2==0){
  81. auto it = find(a.begin(),a.end(),val);
  82. a.push_front(val);
  83. a.erase(it);
  84. }else{
  85. auto it = find(a.begin(),a.end(),val);
  86. a.push_back(val);
  87. a.erase(it);
  88. }
  89. }else if(z==2){
  90. int p,y;
  91. cin>>y>>p;
  92. --y;
  93. a[y] = p;
  94. }else{
  95. int l,r,k;
  96. cin>>l>>r>>k;
  97. --l;--r;
  98.  
  99. Q[j].i = j;
  100. Q[j].l = l;
  101. Q[j].r = r;
  102. Q[j].k = k;
  103. j++;
  104. }
  105. // for(int i = 0;i<n;i++){
  106. // cout<<a[i]<<" ";
  107. // }
  108. // cout<<endl;
  109. }
  110. cout<<j<<endl;
  111.  
  112.  
  113. sort(Q , Q+j , comp);
  114.  
  115. int ML = 0 , MR = -1;
  116. for(int i=0;i<j;i++){
  117. int L = Q[i].l;
  118. int R = Q[i].r;
  119.  
  120. while(ML < L)
  121. remove(ML,i) , ML++;
  122.  
  123. while(ML > L)
  124. ML-- , add(ML,i);
  125.  
  126. while(MR < R)
  127. MR++ , add(MR,i);
  128.  
  129. while(MR > R)
  130. remove(MR,i) , MR--;
  131.  
  132. ans[Q[i].i] = cnt;
  133. }
  134.  
  135. for(int i=0;i<j;i++)
  136. cout<<ans[i]<<endl;
  137.  
  138.  
  139. }
  140. }
  141.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement