From 088387d5e408cee5805558fa8c1feb54ce0615f3 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 8 Dec 2022 20:24:08 +0800 Subject: [PATCH] D - Jzzhu and Numbers https://codeforces.com/contest/449/submission/184326882 --- Codeforces/449/449.cpp | 52 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 Codeforces/449/449.cpp diff --git a/Codeforces/449/449.cpp b/Codeforces/449/449.cpp new file mode 100644 index 00000000..39f0970e --- /dev/null +++ b/Codeforces/449/449.cpp @@ -0,0 +1,52 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int mod = 1e9 + 7; + +int n, s[1 << 20], ans; + +int binpow(int a, int b) { + int res = 1; + + while (b) { + if (b & 1) res = static_cast(res) * a % mod; + a = static_cast(a) * a % mod; + b >>= 1; + } + + return res; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n; + + for (int i = 1, x; i <= n; i++) { + cin >> x; + + s[(1 << 20) - 1 - x]++; + } + + for (int i = 0; i < 20; i++) { + for (int j = 0; j < 1 << 20; j++) { + if (j & (1 << i)) { + s[j] += s[j ^ (1 << i)]; + } + } + } + + ans = binpow(2, n); + + for (int i = 0; i < (1 << 20) - 1; i++) { + ans = (static_cast(ans) + (__builtin_popcount(i) % 2 ? -1 : 1) * binpow(2, s[i])) % mod; + } + + cout << (ans + mod) % mod << endl; + + return 0; +}