fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int N = 100005;
  5. const int A = 1000000;
  6.  
  7. int a[N];
  8. int cnt[A + 1];
  9. int n;
  10.  
  11. map<int,int> mp;
  12.  
  13. int sub1()
  14. {
  15. for(int i = 1; i <= n; i++)
  16. {
  17. cnt[a[i]]++;
  18. }
  19.  
  20. for(int i = 0; i <= A; i++)
  21. {
  22. if(cnt[i] % 2 == 1)
  23. return i;
  24. }
  25. }
  26.  
  27. int sub2_solve1()
  28. {
  29. for(int i = 1; i <= n; i++)
  30. {
  31. mp[a[i]]++;
  32. }
  33.  
  34. for(pair<int,int> x:mp)
  35. {
  36. if(x.second % 2 == 1)
  37. return x.first;
  38. }
  39. }
  40.  
  41. int sub2_solve2()
  42. {
  43. sort(a + 1, a + 1 + n);
  44.  
  45. int cnt = 1;
  46. for (int i = 2; i <= n; i++)
  47. {
  48. if (a[i] == a[i - 1])
  49. {
  50. ++cnt;
  51. }
  52.  
  53. else
  54. {
  55. if (cnt % 2 == 1) return a[i - 1];
  56. cnt = 1;
  57. }
  58. }
  59.  
  60. if (cnt % 2 == 1) return a[n];
  61. }
  62.  
  63. int sub2_solve3()
  64. {
  65. int ans = 0;
  66.  
  67. for(int i = 1; i <= n; i++)
  68. {
  69. ans ^= a[i];
  70. }
  71.  
  72. return ans;
  73. }
  74.  
  75. int main() {
  76. ios_base::sync_with_stdio(false);
  77. cin.tie(nullptr);
  78. cout.tie(nullptr);
  79. freopen("CHIECGIAY.INP", "r", stdin);
  80. freopen("CHIECGIAY.OUT", "w", stdout);
  81. cin >> n;
  82. int MaxA = -1;
  83. for(int i = 1; i <= n; i++)
  84. {
  85. cin >> a[i];
  86. MaxA = max(MaxA, a[i]);
  87. }
  88.  
  89. if (MaxA <= 1e6) cout<<sub1();
  90. else cout<<sub2_solve3();
  91.  
  92. return 0;
  93. }
  94.  
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
Standard output is empty