Submission #635361

#TimeUsernameProblemLanguageResultExecution timeMemory
635361CyanmondParty (INOI20_party)C++17
23 / 100
3081 ms372 KiB
#include <bits/stdc++.h> using i64 = long long; constexpr i64 mod = 1000000007; i64 nmr(i64 a) { a %= mod; if (a < 0) a += mod; return a; } i64 add(i64 a, i64 b) { a += b; if (a > mod) a -= mod; return a; } i64 mul(i64 a, i64 b) { return a * b % mod; } void add_m(i64 &a, i64 b) { a = add(a, b); } void mul_m(i64 &a, i64 b) { a = mul(a, b); } i64 inv(i64 x) { i64 a = x, b = mod, u = 1, v = 0, t = 0; while (b > 0) { t = a / b; a -= t * b; u -= t * v; std::swap(a, b); std::swap(u, v); } return nmr(u); } i64 pow(i64 a, i64 n) { i64 ret = 1; while (n != 0) { if (n & 1) mul_m(ret, a); mul_m(a, a); n >>= 1; } return ret; } std::unordered_map<i64, i64> memo; void solve() { i64 N; std::cin >> N; if (memo.find(N) != memo.end()) { std::cout << memo[N] << std::endl; return; } // N = 2 ^ k - 1 i64 k = 0; while ((1ll << k) - 1 < N) ++k; // assert((1ll << k) - 1 == N); i64 res = 0; for (i64 d = 0; d < k; ++d) { i64 ms = nmr(1ll << d); i64 sum = 0; for (i64 u = 0; u <= 2 * k; ++u) { i64 count_v = 0; for (i64 p = 0; p <= u; ++p) { const i64 now_d = d - p; if (now_d < 0) continue; const i64 t = u - p; if (now_d + t >= k) continue; i64 c = 1ll << t; if (p != 0 and t != 0) c /= 2; count_v += c; } add_m(res, mul(mul(ms, u), add(pow(2, N - sum), mod - pow(2, N - sum - count_v)))); sum += count_v; } } mul_m(res, inv(add(pow(2, N), mod - 1))); std::cout << res << std::endl; memo[N] = res; } int main() { std::ios::sync_with_stdio(false); std::cin.tie(nullptr); int Q; std::cin >> Q; while (Q--) solve(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...