Submission #1003410

# Submission time Handle Problem Language Result Execution time Memory
1003410 2024-06-20T09:57:08 Z vjudge1 Party (INOI20_party) C++17
30 / 100
2946 ms 8532 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define endl "\n"
 
using namespace std;
using namespace __gnu_pbds;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T> using ordered_set = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll mod = 1e9 + 7, N = 1e6 + 5;
ll pw[N], n;
ll freq[120];
void precomp()
{
    pw[0] = 1;
    for (ll i = 1; i < N; i++) pw[i] = pw[i - 1] * 2 % mod;
}
ll binpow(ll n, ll p)
{
    ll ans = 1;
    while (p)
    {
        ans = (p & 1 ? (ans * n) % mod : ans);
        n = (n * n) % mod;
        p >>= 1;
    }
    return ans;
}
ll pww(ll p)
{
    if (p < N) return pw[p];
    if (p & 1) 
    {
        p = pww(p >> 1);
        return p * p * 2 % mod;
    }
    p = pww(p >> 1);
    return p * p % mod;
}
ll inv(ll x)
{
    return binpow(x, mod - 2);
}
void dfs(ll v, ll par = 0, ll depth = 0)
{
    freq[depth]++;
    for (ll to : {v >> 1, v * 2, v * 2 + 1}) if (to != par and to <= n and to >= 1) dfs(to, v, depth + 1);
}
void solve()
{
    cin >> n;
    if (n <= 200){
    ll ans = 0;
    for (ll i = 1; i <= n; i++)
    {
        for (ll j = 0; j < 20; j++) freq[j] = 0;
        dfs(i);
        ll cur = 0;
        for (ll j = 19; j >= 0; j--)
            ans = (ans + binpow(2, cur) * (binpow(2, freq[j]) - 1) % mod * j % mod) % mod, cur += freq[j];
    }
    ans = ans * inv(binpow(2, n) - 1 + mod) % mod;
    cout << ans << endl;
        
    }
    else
    {
        ll ans = 0, lg = __lg(n);
    ll freq[120];
    for (ll i = 0; i <= lg; i++)
    {
        ll res = 0;
        for (ll j = 0; j < 120; j++) freq[j] = 0;
        for (ll j = 1; j <= i; j++){
            freq[j]++;
            for (ll x = 1; i - j + x <= lg; x++) freq[j + x] += (1ll << (x - 1));
        }
        for (ll x = 1; x + i <= lg; x++) freq[x] += (1ll << x);
        ll cur = 0;
        for (ll j = 119; j >= 0; j--)
            res = (res + pww(cur) * (pww(freq[j]) - 1) % mod * j % mod) % mod, cur += freq[j];
        ans = (ans + binpow(2, i) * res % mod) % mod;
    }
    ans = ans * inv(binpow(2, n) - 1 + mod) % mod;
    cout << ans << endl;
    }
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll t = 1;
    precomp();
    cin >> t;
    for (ll cs = 1; cs <= t; cs++)
        solve();
    // cerr << "\nTime elapsed: " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms\n";
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8284 KB Output is correct
2 Correct 10 ms 8288 KB Output is correct
3 Correct 11 ms 8284 KB Output is correct
4 Correct 11 ms 8284 KB Output is correct
5 Correct 12 ms 8284 KB Output is correct
6 Correct 11 ms 8284 KB Output is correct
7 Correct 11 ms 8284 KB Output is correct
8 Correct 12 ms 8284 KB Output is correct
9 Correct 11 ms 8056 KB Output is correct
10 Correct 13 ms 8244 KB Output is correct
11 Correct 279 ms 8284 KB Output is correct
12 Correct 253 ms 8280 KB Output is correct
13 Correct 251 ms 8280 KB Output is correct
14 Correct 285 ms 8280 KB Output is correct
15 Correct 259 ms 8288 KB Output is correct
16 Correct 252 ms 8296 KB Output is correct
17 Correct 165 ms 8280 KB Output is correct
18 Correct 167 ms 8532 KB Output is correct
19 Correct 155 ms 8280 KB Output is correct
20 Correct 157 ms 8288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 66 ms 8284 KB Output is correct
2 Correct 82 ms 8284 KB Output is correct
3 Correct 70 ms 8284 KB Output is correct
4 Correct 57 ms 8284 KB Output is correct
5 Correct 72 ms 8284 KB Output is correct
6 Correct 70 ms 8280 KB Output is correct
7 Correct 69 ms 8284 KB Output is correct
8 Correct 66 ms 8284 KB Output is correct
9 Correct 63 ms 8284 KB Output is correct
10 Correct 68 ms 8280 KB Output is correct
11 Correct 2739 ms 8280 KB Output is correct
12 Correct 2706 ms 8308 KB Output is correct
13 Correct 2856 ms 8280 KB Output is correct
14 Correct 2894 ms 8324 KB Output is correct
15 Correct 2946 ms 8288 KB Output is correct
16 Correct 2695 ms 8308 KB Output is correct
17 Correct 2763 ms 8288 KB Output is correct
18 Correct 2835 ms 8284 KB Output is correct
19 Correct 2653 ms 8324 KB Output is correct
20 Correct 2718 ms 8320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 58 ms 8028 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 8284 KB Output is correct
2 Correct 10 ms 8288 KB Output is correct
3 Correct 11 ms 8284 KB Output is correct
4 Correct 11 ms 8284 KB Output is correct
5 Correct 12 ms 8284 KB Output is correct
6 Correct 11 ms 8284 KB Output is correct
7 Correct 11 ms 8284 KB Output is correct
8 Correct 12 ms 8284 KB Output is correct
9 Correct 11 ms 8056 KB Output is correct
10 Correct 13 ms 8244 KB Output is correct
11 Correct 279 ms 8284 KB Output is correct
12 Correct 253 ms 8280 KB Output is correct
13 Correct 251 ms 8280 KB Output is correct
14 Correct 285 ms 8280 KB Output is correct
15 Correct 259 ms 8288 KB Output is correct
16 Correct 252 ms 8296 KB Output is correct
17 Correct 165 ms 8280 KB Output is correct
18 Correct 167 ms 8532 KB Output is correct
19 Correct 155 ms 8280 KB Output is correct
20 Correct 157 ms 8288 KB Output is correct
21 Correct 66 ms 8284 KB Output is correct
22 Correct 82 ms 8284 KB Output is correct
23 Correct 70 ms 8284 KB Output is correct
24 Correct 57 ms 8284 KB Output is correct
25 Correct 72 ms 8284 KB Output is correct
26 Correct 70 ms 8280 KB Output is correct
27 Correct 69 ms 8284 KB Output is correct
28 Correct 66 ms 8284 KB Output is correct
29 Correct 63 ms 8284 KB Output is correct
30 Correct 68 ms 8280 KB Output is correct
31 Correct 2739 ms 8280 KB Output is correct
32 Correct 2706 ms 8308 KB Output is correct
33 Correct 2856 ms 8280 KB Output is correct
34 Correct 2894 ms 8324 KB Output is correct
35 Correct 2946 ms 8288 KB Output is correct
36 Correct 2695 ms 8308 KB Output is correct
37 Correct 2763 ms 8288 KB Output is correct
38 Correct 2835 ms 8284 KB Output is correct
39 Correct 2653 ms 8324 KB Output is correct
40 Correct 2718 ms 8320 KB Output is correct
41 Incorrect 58 ms 8028 KB Output isn't correct
42 Halted 0 ms 0 KB -