fork download
  1. #include "bits/stdc++.h"
  2. using namespace std;
  3.  
  4. #ifdef Nero
  5. #include "Deb.h"
  6. #else
  7. #define deb(...)
  8. #endif
  9.  
  10. signed main(){
  11. ios::sync_with_stdio(false);
  12. cin.tie(nullptr);
  13. int q;
  14. cin >> q;
  15. set<int> se;
  16. multiset<int> ans;
  17. auto ins = [&](int x) {
  18. auto it = se.insert(x).first;
  19. auto la = (it == se.begin() ? prev(se.end()) : prev(it));
  20. auto nx = (next(it) == se.end() ? se.begin() : next(it));
  21. if (se.size() > 1) {
  22. ans.insert(x ^ *la);
  23. ans.insert(x ^ *nx);
  24. }
  25. if (se.size() > 2) {
  26. ans.erase(ans.find(*la ^ *nx));
  27. }
  28. };
  29. auto rem = [&](int x) {
  30. auto it = se.find(x);
  31. auto la = (it == se.begin() ? prev(se.end()) : prev(it));
  32. auto nx = (next(it) == se.end() ? se.begin() : next(it));
  33. ans.insert(*la ^ *nx);
  34. if (se.size() > 2) {
  35. ans.erase(ans.find(x ^ *la));
  36. ans.erase(ans.find(x ^ *nx));
  37. }
  38. se.erase(x);
  39. };
  40. multiset<int> occ;
  41. map<int, int> freq;
  42. while (q--) {
  43. int t;
  44. cin >> t;
  45. if (t == 1) {
  46. int x;
  47. cin >> x;
  48. if (freq.count(x)) {
  49. occ.erase(occ.find(freq[x]));
  50. }
  51. freq[x]++;
  52. occ.insert(freq[x]);
  53. if (freq[x] == 1) {
  54. ins(x);
  55. }
  56. } else if (t == 2) {
  57. int x;
  58. cin >> x;
  59. occ.erase(occ.find(freq[x]));
  60. freq[x]--;
  61. occ.insert(freq[x]);
  62. if (freq[x] == 0) {
  63. rem(x);
  64. }
  65. } else {
  66. if (*occ.rbegin() > 1) {
  67. cout << 0 << '\n';
  68. } else {
  69. cout << *ans.begin() << '\n';
  70. }
  71. }
  72. }
  73. return 0;
  74. }
  75.  
Runtime error #stdin #stdout 0.01s 5456KB
stdin
Standard input is empty
stdout
Standard output is empty