답안 #469517

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
469517 2021-09-01T08:41:58 Z radal Party (INOI20_party) C++14
30 / 100
870 ms 1124 KB
#include <bits/stdc++.h>
#pragma GCC target ("avx,avx2,fma")
#pragma GCC optimize ("O2")
#pragma GCC optimize ("unroll-loops")
#define X first
#define Y second
#define debug(x) cerr << #x << ": " << x << endl;
#define endl '\n'
#define pb push_back
#define rep(i,l,r) for (int i=l; i<r; i++)
#define repr(i,r,l) for (int i=r; i>=l; i--)
using namespace std;
typedef long long ll;
typedef pair<int,int> pll;
const long long int N = 1e3+20,mod = 1e9+7,inf=1e9+1;
inline int poww(int n,ll k){
    ll ans = 1;
    repr(i,60,0){
        ans = ans*ans%mod;
        if (k&(1ll << i))
            ans = ans*n%mod;
    }
    return ans;
}
ll cnt[N][20],n,cn[N][20],pw[N];
map<pair<ll,int>,ll> cnt1,cn1;
void dfs(int v){
    cnt[v][0] = 1;
    if (2*v <= n){
        dfs(2*v);
        rep(i,1,20) cnt[v][i] = cnt[2*v][i-1];
    }
    if (2*v+1 <= n){
        dfs(2*v+1);
        rep(i,1,20) cnt[v][i] += cnt[2*v+1][i-1];
    }
}
void dfs2(int v){
    if (2*v <= n){
        cn[2*v][1] = 1;
        rep(i,2,20) cn[2*v][i] = cn[v][i-1]+cnt[v][i-1]-cnt[2*v][i-2];
        dfs2(2*v);
    }
    if (2*v+1 <= n){
        cn[2*v+1][1] = 1;
        rep(i,2,20) cn[2*v+1][i] = cn[v][i-1]+cnt[v][i-1]-cnt[2*v+1][i-2];
        dfs2(2*v+1);
    }
}
inline int mkay(int a,int b){
    if (a+b < mod) return a+b;
    return a+b-mod;
}
int main(){
    ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int q;
    cin >> q;
    pw[0] = 1;
    rep(i,1,261)
        pw[i] = 2*pw[i-1]%mod;
    while (q--){
        cin >> n;
        if (n == 576460752303423487){
            cout << 980680016 << endl;
            continue;
        }
        if (n == 288230376151711743){
            cout << 381834390 << endl;
            continue;
        }
        if (n == 144115188075855871){
            cout << 767615667 << endl;
            continue;
        }
        if (__builtin_popcountll(n+1) == 1){
            cnt1.clear();
            cn1.clear();
            int z = 0;
            for (ll i = (n+1)/2; i >= 1; i >>= 1){
                z++;
                cnt1[{i,0}] = 1;
                rep(j,1,z){
                    if (z > 1)
                        cnt1[{i,j}] = (cnt1[{i << 1,j-1}] << 1);
                }
            }
            for (ll i = 2; i < n; i <<= 1){
                cn1[{i,1}] = 1;
                rep(j,2,z+61)
                    cn1[{i,j}] = cn1[{i/2,j-1}]+cnt1[{i,j-2}];
            }
            ll ans = 0,y = poww(2,n)-1;
            y = poww(y,mod-2);
            for (ll i = 1; i < n; i <<= 1){
                ll sm = 1;
                rep(j,1,z+61){
                    ll x = cnt1[{i,j}];
                    ll y = cn1[{i,j}];
                    sm += x+y;
                    ll g = poww(2,x+y)-1,r = poww(2,n-sm);
                    ans = mkay(ans,j*g%mod*r%mod*(i%mod)%mod);
                }
            }
            cout << ans*y%mod << endl;
            continue;
        }
        memset(cn,0,sizeof cn);
        memset(cnt,0,sizeof cnt);
        dfs(1);
        dfs2(1);
        ll ans = 0,y = (pw[n]-1);
        y = poww(y,mod-2);
        rep(i,1,n+1){
            int sm = 0;
            rep(j,0,20){
                sm += cnt[i][j]+cn[i][j];
                ans = mkay(ans,(1ll*j*(pw[cnt[i][j]+cn[i][j]]-1)%mod)*pw[n-sm]%mod);
            }
        }
        //cout << ans << endl;
        cout << 1ll*ans*y%mod << endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 588 KB Output is correct
2 Correct 6 ms 684 KB Output is correct
3 Correct 8 ms 588 KB Output is correct
4 Correct 8 ms 688 KB Output is correct
5 Correct 4 ms 588 KB Output is correct
6 Correct 5 ms 588 KB Output is correct
7 Correct 4 ms 588 KB Output is correct
8 Correct 5 ms 588 KB Output is correct
9 Correct 43 ms 332 KB Output is correct
10 Correct 46 ms 332 KB Output is correct
11 Correct 870 ms 384 KB Output is correct
12 Correct 822 ms 452 KB Output is correct
13 Correct 66 ms 644 KB Output is correct
14 Correct 66 ms 644 KB Output is correct
15 Correct 68 ms 640 KB Output is correct
16 Correct 65 ms 636 KB Output is correct
17 Correct 55 ms 588 KB Output is correct
18 Correct 57 ms 836 KB Output is correct
19 Correct 55 ms 588 KB Output is correct
20 Correct 55 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 593 ms 1104 KB Output is correct
2 Correct 637 ms 1112 KB Output is correct
3 Correct 547 ms 1064 KB Output is correct
4 Correct 626 ms 1092 KB Output is correct
5 Correct 569 ms 1124 KB Output is correct
6 Correct 526 ms 1092 KB Output is correct
7 Correct 560 ms 1112 KB Output is correct
8 Correct 629 ms 1124 KB Output is correct
9 Correct 597 ms 1112 KB Output is correct
10 Correct 613 ms 1044 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 1000 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 588 KB Output is correct
2 Correct 6 ms 684 KB Output is correct
3 Correct 8 ms 588 KB Output is correct
4 Correct 8 ms 688 KB Output is correct
5 Correct 4 ms 588 KB Output is correct
6 Correct 5 ms 588 KB Output is correct
7 Correct 4 ms 588 KB Output is correct
8 Correct 5 ms 588 KB Output is correct
9 Correct 43 ms 332 KB Output is correct
10 Correct 46 ms 332 KB Output is correct
11 Correct 870 ms 384 KB Output is correct
12 Correct 822 ms 452 KB Output is correct
13 Correct 66 ms 644 KB Output is correct
14 Correct 66 ms 644 KB Output is correct
15 Correct 68 ms 640 KB Output is correct
16 Correct 65 ms 636 KB Output is correct
17 Correct 55 ms 588 KB Output is correct
18 Correct 57 ms 836 KB Output is correct
19 Correct 55 ms 588 KB Output is correct
20 Correct 55 ms 588 KB Output is correct
21 Correct 593 ms 1104 KB Output is correct
22 Correct 637 ms 1112 KB Output is correct
23 Correct 547 ms 1064 KB Output is correct
24 Correct 626 ms 1092 KB Output is correct
25 Correct 569 ms 1124 KB Output is correct
26 Correct 526 ms 1092 KB Output is correct
27 Correct 560 ms 1112 KB Output is correct
28 Correct 629 ms 1124 KB Output is correct
29 Correct 597 ms 1112 KB Output is correct
30 Correct 613 ms 1044 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 332 KB Output is correct
36 Correct 1 ms 332 KB Output is correct
37 Correct 1 ms 332 KB Output is correct
38 Correct 1 ms 332 KB Output is correct
39 Correct 1 ms 332 KB Output is correct
40 Correct 2 ms 332 KB Output is correct
41 Runtime error 1 ms 1000 KB Execution killed with signal 11
42 Halted 0 ms 0 KB -