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