/********************************* ***** Common v2.0.8 ***** *********************************/ #include <bits/stdc++.h> void test(); namespace common { template<typename T> T gcd(T const &a, T const &b) { return b == 0 ? a : gcd(b, a%b); } namespace io { template<typename T> inline std::ostream& operator<< (std::ostream& out, const std::vector<T>& data) { if(data.size() > 0) { out << data[0]; for( auto it = data.begin()+1; it != data.end(); it++ ) out << ' ' << *it; } return out; } template<typename T> inline std::istream& operator>> (std::istream& in, std::vector<T>& data) { for( auto &v : data ) in >> v; return in; } template<typename A, typename B> inline std::ostream& operator<< (std::ostream& out, const std::pair<A, B>& data) { return out << data.first << ' ' << data.second; } template<typename A, typename B> inline std::istream& operator>> (std::istream& in, std::pair<A, B>& data) { return in >> data.first >> data.second; } } template<typename T> class vector_from_one : public std::vector<T> { public: using std::vector<T>::vector; T& operator[] (size_t n) { return std::vector<T>::operator[](n-1); } const T& operator[] (size_t n) const { return std::vector<T>::operator[](n-1); } T& at (size_t n) { return std::vector<T>::at(n-1); } const T& at (size_t n) const { return std::vector<T>::at(n-1); } }; namespace functional { template<typename Type, typename C> struct GetComparator { using Comparator = C; }; template<typename Type> struct GetComparator<Type, void> { using Comparator = std::less<Type>; }; template<typename Object, typename Type, Type Object::* default_field, typename Comparator = void> struct CompareField { const Type Object::* field; CompareField() : field(default_field) {} CompareField(Type Object::* field) : field(field) {} constexpr bool operator()(Object const &lhs, Object const &rhs) const { return typename GetComparator<Type, Comparator>::Comparator()(lhs.*field, rhs.*field); } }; template<typename Comparator = void, typename Object, typename Type> const CompareField<Object, Type, nullptr, Comparator> compare_field(Type Object::* field) { return {field}; } template<typename iterator_type> class Iterable { typedef iterator_type iterator; const iterator begin_iterator; const iterator end_iterator; public: Iterable(iterator begin, iterator end) : begin_iterator(begin), end_iterator(end) {} iterator begin() { return begin_iterator; } iterator end() { return end_iterator; } }; template<typename iterator> Iterable<iterator> iterable(iterator begin, iterator end){ return Iterable<iterator>(begin, end); } template<typename Collection> auto reversed(Collection &collection) -> Iterable<decltype(collection.rbegin())> { return iterable(collection.rbegin(), collection.rend()); } } namespace operators { struct base_operator {}; template <typename LHS, typename OP> struct operator_proxy { LHS lhs; OP op; }; template <typename LHS, typename OP, typename SFINAE = typename std::enable_if<std::is_base_of<base_operator, typename std::remove_reference<OP>::type>::value>::type> operator_proxy<LHS, OP> operator<(LHS &&lhs, OP &&op) { return {lhs, op}; } template <typename LHS, typename OP, typename RHS> auto operator>(operator_proxy<LHS, OP> proxy, RHS &&rhs) -> decltype(proxy.op(proxy.lhs, rhs)) { proxy.op(proxy.lhs, rhs); } struct : public base_operator { template <typename T> void operator()(T &x, T y) const { x = std::max(x, y); } } const set_if_greater; struct : public base_operator { template <typename T> void operator()(T &x, T y) const { x = std::min(x, y); } } const set_if_less; } namespace main { int _default(int const, char const * const[]) { std::cout << "Undefined common::main app!" << std::endl; return 1; } int (*_app)(int const, char const * const[]); class one { static int main(int const argc, char const * const argv[]) { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); test(); return 0; } public: one() { _app = main; } }; class many { static int main(int const argc, char const * const argv[]) { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int T; std::cin >> T; while( T --> 0 ) test(); return 0; } public: many() { _app = main; } }; class all { static int main(int const argc, char const * const argv[]) { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cin.exceptions(std::ifstream::eofbit); try { while(std::cin) test(); } catch (std::ifstream::failure&) {} return 0; } public: all() { _app = main; } }; } } int main(int const argc, char const * const argv[]) { return common::main::_app(argc, argv); } using namespace std; using namespace common; using namespace common::io; using namespace common::functional; using namespace common::operators; // end of #include <common.hpp> //==================================================== main::one _; void test() { int n; cin >> n; vector<int> counts(202000); int high = 0; while (n --> 0) { int val; cin >> val; high <set_if_greater> val; ++counts[val]; } for (int i = 0; i <= high; ++i) { assert(i < (int) counts.size()); int carry = counts[i] / 2; if (carry > 0) high <set_if_greater> i+1; counts[i+1] += carry; // counts[i] %= 2; } cout << high << endl; }
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 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 | /********************************* ***** Common v2.0.8 ***** *********************************/ #include <bits/stdc++.h> void test(); namespace common { template<typename T> T gcd(T const &a, T const &b) { return b == 0 ? a : gcd(b, a%b); } namespace io { template<typename T> inline std::ostream& operator<< (std::ostream& out, const std::vector<T>& data) { if(data.size() > 0) { out << data[0]; for( auto it = data.begin()+1; it != data.end(); it++ ) out << ' ' << *it; } return out; } template<typename T> inline std::istream& operator>> (std::istream& in, std::vector<T>& data) { for( auto &v : data ) in >> v; return in; } template<typename A, typename B> inline std::ostream& operator<< (std::ostream& out, const std::pair<A, B>& data) { return out << data.first << ' ' << data.second; } template<typename A, typename B> inline std::istream& operator>> (std::istream& in, std::pair<A, B>& data) { return in >> data.first >> data.second; } } template<typename T> class vector_from_one : public std::vector<T> { public: using std::vector<T>::vector; T& operator[] (size_t n) { return std::vector<T>::operator[](n-1); } const T& operator[] (size_t n) const { return std::vector<T>::operator[](n-1); } T& at (size_t n) { return std::vector<T>::at(n-1); } const T& at (size_t n) const { return std::vector<T>::at(n-1); } }; namespace functional { template<typename Type, typename C> struct GetComparator { using Comparator = C; }; template<typename Type> struct GetComparator<Type, void> { using Comparator = std::less<Type>; }; template<typename Object, typename Type, Type Object::* default_field, typename Comparator = void> struct CompareField { const Type Object::* field; CompareField() : field(default_field) {} CompareField(Type Object::* field) : field(field) {} constexpr bool operator()(Object const &lhs, Object const &rhs) const { return typename GetComparator<Type, Comparator>::Comparator()(lhs.*field, rhs.*field); } }; template<typename Comparator = void, typename Object, typename Type> const CompareField<Object, Type, nullptr, Comparator> compare_field(Type Object::* field) { return {field}; } template<typename iterator_type> class Iterable { typedef iterator_type iterator; const iterator begin_iterator; const iterator end_iterator; public: Iterable(iterator begin, iterator end) : begin_iterator(begin), end_iterator(end) {} iterator begin() { return begin_iterator; } iterator end() { return end_iterator; } }; template<typename iterator> Iterable<iterator> iterable(iterator begin, iterator end){ return Iterable<iterator>(begin, end); } template<typename Collection> auto reversed(Collection &collection) -> Iterable<decltype(collection.rbegin())> { return iterable(collection.rbegin(), collection.rend()); } } namespace operators { struct base_operator {}; template <typename LHS, typename OP> struct operator_proxy { LHS lhs; OP op; }; template <typename LHS, typename OP, typename SFINAE = typename std::enable_if<std::is_base_of<base_operator, typename std::remove_reference<OP>::type>::value>::type> operator_proxy<LHS, OP> operator<(LHS &&lhs, OP &&op) { return {lhs, op}; } template <typename LHS, typename OP, typename RHS> auto operator>(operator_proxy<LHS, OP> proxy, RHS &&rhs) -> decltype(proxy.op(proxy.lhs, rhs)) { proxy.op(proxy.lhs, rhs); } struct : public base_operator { template <typename T> void operator()(T &x, T y) const { x = std::max(x, y); } } const set_if_greater; struct : public base_operator { template <typename T> void operator()(T &x, T y) const { x = std::min(x, y); } } const set_if_less; } namespace main { int _default(int const, char const * const[]) { std::cout << "Undefined common::main app!" << std::endl; return 1; } int (*_app)(int const, char const * const[]); class one { static int main(int const argc, char const * const argv[]) { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); test(); return 0; } public: one() { _app = main; } }; class many { static int main(int const argc, char const * const argv[]) { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); int T; std::cin >> T; while( T --> 0 ) test(); return 0; } public: many() { _app = main; } }; class all { static int main(int const argc, char const * const argv[]) { std::ios_base::sync_with_stdio(false); std::cin.tie(NULL); std::cin.exceptions(std::ifstream::eofbit); try { while(std::cin) test(); } catch (std::ifstream::failure&) {} return 0; } public: all() { _app = main; } }; } } int main(int const argc, char const * const argv[]) { return common::main::_app(argc, argv); } using namespace std; using namespace common; using namespace common::io; using namespace common::functional; using namespace common::operators; // end of #include <common.hpp> //==================================================== main::one _; void test() { int n; cin >> n; vector<int> counts(202000); int high = 0; while (n --> 0) { int val; cin >> val; high <set_if_greater> val; ++counts[val]; } for (int i = 0; i <= high; ++i) { assert(i < (int) counts.size()); int carry = counts[i] / 2; if (carry > 0) high <set_if_greater> i+1; counts[i+1] += carry; // counts[i] %= 2; } cout << high << endl; } |