fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. bool on(int mask,int i)
  5. {
  6. return (mask>>i)&1;
  7. }
  8. int get(int x,int k)
  9. {
  10. int cnt=0;
  11. for(int i=20;i>=0;i--)
  12. {
  13. if(on(x,i)&&(cnt|(1<<i))<=k)
  14. {
  15. cnt+=1<<i;
  16. x^=1<<i;
  17. }
  18. }
  19. return x;
  20. }
  21. signed main()
  22. {
  23. ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  24. int n,k;cin>>n>>k;
  25. multiset<int>ms;
  26. for(int mask=0;mask<(1<<20);mask++)
  27. {
  28. ms.insert(get(mask,k));
  29. if(mask<=10)
  30. {
  31. cout<<get(mask,k)<<'\n';
  32. }
  33. }
  34. return 0;
  35. map<int,bool>op;
  36. while(n--)
  37. {
  38. int x;cin>>x;
  39. if(op[x]==0)
  40. {
  41. op[x]=1;
  42. ms.erase(ms.find(get(x,k)));
  43. }
  44. else
  45. {
  46. op[x]=0;
  47. ms.insert(get(x,k));
  48. }
  49. cout<<*ms.begin()<<'\n';
  50. }
  51. return 0;
  52. }
Success #stdin #stdout 0.37s 52756KB
stdin
Standard input is empty
stdout
0
0
0
0
0
0
0
0
0
0
0