#include <iostream> int main(int argc, char** argv) { long long n; unsigned long long a; unsigned long long *sum; unsigned long long size = (201718 * 20 / (8 * sizeof(unsigned long long))) + 1; sum = new unsigned long long[size]; for (unsigned long long i = 0; i < size; i++) { sum[i] = 0; } std::cin >> n; for (long long i = 0; i< n; i++) { std::cin >> a; unsigned long long index = a/64; unsigned long long value = 1ULL << (a%64); if (sum[index] >= -value) { sum[index + 1]++; } sum[index] += value; } unsigned long long max_index = 0; unsigned long long max_value; for (unsigned long long i = 0; i < size; i++) { if (sum[i]) { max_index = i; } } max_value = max_index * 64; unsigned long long temp = sum[max_index]; while (temp >>= 1) { max_value++; } std::cout << max_value; delete [] sum; return 0; }
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 | #include <iostream> int main(int argc, char** argv) { long long n; unsigned long long a; unsigned long long *sum; unsigned long long size = (201718 * 20 / (8 * sizeof(unsigned long long))) + 1; sum = new unsigned long long[size]; for (unsigned long long i = 0; i < size; i++) { sum[i] = 0; } std::cin >> n; for (long long i = 0; i< n; i++) { std::cin >> a; unsigned long long index = a/64; unsigned long long value = 1ULL << (a%64); if (sum[index] >= -value) { sum[index + 1]++; } sum[index] += value; } unsigned long long max_index = 0; unsigned long long max_value; for (unsigned long long i = 0; i < size; i++) { if (sum[i]) { max_index = i; } } max_value = max_index * 64; unsigned long long temp = sum[max_index]; while (temp >>= 1) { max_value++; } std::cout << max_value; delete [] sum; return 0; } |