#include <bits/stdc++.h> using namespace std; using u64 = uint64_t; using i64 = int64_t; // print tuples {{{ template <typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& t) { return os << '[' << t.first << ',' << t.second << ']'; } // }}} // print containers {{{ template <typename It> void print(ostream& os, It begin, It end, u64 len, u64 limit = 30) { u64 count = 0; os << "{"; while (begin != end && count < limit) { os << "(" << *begin << ")"; count++; begin++; } if (begin != end) os << "... " << len << " total"; os << "}"; } #define MAKE_PRINTER_1(container) \ template <typename T> ostream& operator<<(ostream& os, const container<T>& t) { print(os, t.begin(), t.end(), t.size()); return os; } #define MAKE_PRINTER_2(container) \ template <typename T1, typename T2> \ ostream& operator<<(ostream& os, const container<T1, T2>& t) { \ print(os, t.begin(), t.end(), t.size()); \ return os; \ } MAKE_PRINTER_1(vector) MAKE_PRINTER_2(map) MAKE_PRINTER_1(set) MAKE_PRINTER_2(unordered_map) MAKE_PRINTER_1(unordered_set) #undef MAKE_PRINTER_1 #undef MAKE_PRINTER_2 // }}} // read/write {{{ template <typename T> T read() { T e; cin >> e; return e; } void read() {} template <typename T, typename ...Ts> void read(T& v, Ts& ...ts) { v = read<T>(); read(ts...); } template <typename T> vector<T> readv(u64 n) { vector<T> v; for (u64 i = 0; i < n; i++) v.push_back(read<T>()); return v; } template <typename T> struct identity { const T& operator()(const T& t) const { return t; } }; #define PRINTERS(FNAME, OUTP) \ template <typename T> void FNAME(const T& t) { OUTP << t << ' '; } \ void FNAME##ln() { OUTP << '\n'; } \ template <typename T> void FNAME##ln(const T& t) { OUTP << t << '\n'; } \ template <typename T, typename F = identity<typename T::value_type>> \ void FNAME##v(const T& t, F f = F()) { for (const auto& e : t) FNAME(f(e)); FNAME##ln(); } PRINTERS(print, cout) #ifdef DEBUG_PRINTS PRINTERS(dprint, cerr) #else # define dprint(...) # define dprintv(...) # define dprintln(...) #endif /// }}} void go() { vector<u64> counter(202719); auto n = read<u64>(); for (u64 i = 0; i < n; i++) counter[read<u64>()]++; u64 a = 0; u64 max_nonzero = 0; for (u64 i = 0; i < counter.size(); i++) { a += counter[i]; if (a > 0) max_nonzero = i; a /= 2; } println(max_nonzero); } int main () { // {{{ ios_base::sync_with_stdio(0); cin.tie(0); go(); } //
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 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | #include <bits/stdc++.h> using namespace std; using u64 = uint64_t; using i64 = int64_t; // print tuples {{{ template <typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& t) { return os << '[' << t.first << ',' << t.second << ']'; } // }}} // print containers {{{ template <typename It> void print(ostream& os, It begin, It end, u64 len, u64 limit = 30) { u64 count = 0; os << "{"; while (begin != end && count < limit) { os << "(" << *begin << ")"; count++; begin++; } if (begin != end) os << "... " << len << " total"; os << "}"; } #define MAKE_PRINTER_1(container) \ template <typename T> ostream& operator<<(ostream& os, const container<T>& t) { print(os, t.begin(), t.end(), t.size()); return os; } #define MAKE_PRINTER_2(container) \ template <typename T1, typename T2> \ ostream& operator<<(ostream& os, const container<T1, T2>& t) { \ print(os, t.begin(), t.end(), t.size()); \ return os; \ } MAKE_PRINTER_1(vector) MAKE_PRINTER_2(map) MAKE_PRINTER_1(set) MAKE_PRINTER_2(unordered_map) MAKE_PRINTER_1(unordered_set) #undef MAKE_PRINTER_1 #undef MAKE_PRINTER_2 // }}} // read/write {{{ template <typename T> T read() { T e; cin >> e; return e; } void read() {} template <typename T, typename ...Ts> void read(T& v, Ts& ...ts) { v = read<T>(); read(ts...); } template <typename T> vector<T> readv(u64 n) { vector<T> v; for (u64 i = 0; i < n; i++) v.push_back(read<T>()); return v; } template <typename T> struct identity { const T& operator()(const T& t) const { return t; } }; #define PRINTERS(FNAME, OUTP) \ template <typename T> void FNAME(const T& t) { OUTP << t << ' '; } \ void FNAME##ln() { OUTP << '\n'; } \ template <typename T> void FNAME##ln(const T& t) { OUTP << t << '\n'; } \ template <typename T, typename F = identity<typename T::value_type>> \ void FNAME##v(const T& t, F f = F()) { for (const auto& e : t) FNAME(f(e)); FNAME##ln(); } PRINTERS(print, cout) #ifdef DEBUG_PRINTS PRINTERS(dprint, cerr) #else # define dprint(...) # define dprintv(...) # define dprintln(...) #endif /// }}} void go() { vector<u64> counter(202719); auto n = read<u64>(); for (u64 i = 0; i < n; i++) counter[read<u64>()]++; u64 a = 0; u64 max_nonzero = 0; for (u64 i = 0; i < counter.size(); i++) { a += counter[i]; if (a > 0) max_nonzero = i; a /= 2; } println(max_nonzero); } int main () { // {{{ ios_base::sync_with_stdio(0); cin.tie(0); go(); } // |