#include <bits/stdc++.h> using namespace std; const int mxn = 5e5 + 10; int n; int t[mxn]; int wyn = -1; int main() { scanf("%d", &n); for(int i = 1; i <= n; i++) { int a; scanf("%d", &a); t[a]++; } int curr = 0; for(int i = 0; i < mxn; i++) { curr += t[i]; if(curr % 2 == 1) wyn = i; curr /= 2; } printf("%d\n", wyn); }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | #include <bits/stdc++.h> using namespace std; const int mxn = 5e5 + 10; int n; int t[mxn]; int wyn = -1; int main() { scanf("%d", &n); for(int i = 1; i <= n; i++) { int a; scanf("%d", &a); t[a]++; } int curr = 0; for(int i = 0; i < mxn; i++) { curr += t[i]; if(curr % 2 == 1) wyn = i; curr /= 2; } printf("%d\n", wyn); } |