fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const long long MaxN = 3e5 + 5;
  5.  
  6. long long q;
  7. multiset<long long> s, t;
  8.  
  9. void input()
  10. {
  11. cin >> q;
  12. }
  13.  
  14. void add(long long x)
  15. {
  16. auto it = s.lower_bound(x);
  17.  
  18. if (it != s.end())
  19. {
  20. t.insert(x ^ *it);
  21. }
  22.  
  23. if (it != s.begin())
  24. {
  25. auto pre = prev(it);
  26.  
  27. if (it != s.end())
  28. {
  29. t.erase(t.find(*pre ^ *it));
  30. }
  31.  
  32. t.insert(*pre ^ x);
  33. }
  34.  
  35. s.insert(x);
  36. }
  37.  
  38. void erase(long long x)
  39. {
  40. auto it = s.find(x);
  41. auto pre = it, nxt = it;
  42.  
  43. if (it != s.begin())
  44. {
  45. pre--;
  46. t.erase(t.find(*pre ^ x));
  47. }
  48.  
  49. nxt++;
  50.  
  51. if (nxt != s.end())
  52. {
  53. t.erase(t.find(x ^ *nxt));
  54. }
  55.  
  56. if (it != s.begin() && nxt != s.end())
  57. {
  58. t.insert(*pre ^ *nxt);
  59. }
  60.  
  61. s.erase(it);
  62. }
  63.  
  64. void solve()
  65. {
  66. while (q--)
  67. {
  68. long long type, x;
  69. cin >> type;
  70.  
  71. if (type == 1)
  72. {
  73. cin >> x;
  74. add(x);
  75. }
  76. else if (type == 2)
  77. {
  78. cin >> x;
  79. erase(x);
  80. }
  81. else
  82. {
  83. cout << *t.begin() << "\n";
  84. }
  85. }
  86. }
  87.  
  88. int main()
  89. {
  90. ios_base::sync_with_stdio(0);
  91. cin.tie(0);
  92.  
  93. input();
  94. solve();
  95.  
  96. return 0;
  97. }
Success #stdin #stdout 0s 5320KB
stdin
Standard input is empty
stdout
Standard output is empty