답안 #966738

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
966738 2024-04-20T09:24:16 Z manizare Party (INOI20_party) C++17
100 / 100
1632 ms 394832 KB
#include <bits/stdc++.h>

#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second 
#define ld long double
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define ll long long 
#define PII pair<pii , pii>
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= (b);i++)
#define per(i , a , b) for(int i=a;i >= (b);i--)
#define deb(x) cout <<#x << " : " << x << "\n" ;
using namespace std ;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll maxn = 1e8+10 + 10,  inf = 1e9+10 , mod = 1e9 + 7 ;
int a2[maxn] ;
ll dp[62][62][122] , pr[130] ;

ll po2(int b){
    if(b==0)return 1 ;
    if(b < maxn)return 1ll*a2[b]; 
    ll v =po2(b/2); 
    v=v *v % mod ;
    if(b&1) v= v*2% mod;
    return v; 
}
ll po(ll a,ll b){
    if(b==0)return 1 ;
    ll v =po(a,b/2); 
    v=v *v % mod ;
    if(b&1) v= v*a % mod;
    return v; 
}
ll ch(ll x ,ll d , ll k){
    if(d==-1)return 0;
    d = min(d , k-x);
    return ((1ll<<(d+1))-1);
}
ll ans =0 , N , d[130] ;
vector <ll> cal(ll p){
    ll x = p , k= 0 ;
    vector <ll> h; 
    while(x*2 <= N){
        x *= 2 ;
        k++;
    }
    rep(i , 0 , k)h.pb((1ll<<i)) ;    
    if((x+(1ll<<k)-1) <= N){
        return h ;
    }
    ll az = (x+(1ll<<k)-1) - N ;
    h.back()-=az;
    return h ; 

}

void f(ll p = 1){
    if(p > N)return ;
    ll x= p , k =0 ;
    while(x*2 <= N){
        k++;
        x*=2 ;
    }
    if((x+(1ll<<k)-1) <= N){
        pr[0] = 0 ;
        rep(i , 1 ,120)pr[i] = pr[i-1] + d[i] ;
        rep(i , 0 , k){
            ll sm = 0 ;
            rep(j , 0 , 120){
                ll t = dp[k][i][j] + (j >= i ? pr[j-i] : 0); 
                if(t == N)break ;
                sm = (sm + po2((N-t)%(mod-1))-1);
                if(sm > mod)sm -= mod ;
            }
            sm += mod;
            if(sm > mod)sm-=mod;
            ans = (ans + sm*po2(i))%mod ;
        }
        return ;
    }
    vector <ll> A = cal(p*2) ;
    vector <ll> B = cal(p*2+1) ;
    ll d2[130] , ls[130] ;
    rep(i , 0 , 120){
        d2[i] =0 ;
        ls[i] = d[i] ;
    }
    d2[1] = 1 ;
    rep(i , 1 , 120){
        d2[i] += d[i-1] ;
    }
    rep(i , 0 , sz(B)-1){
        d2[i+2] += B[i] ;
    }
    rep(i , 0 , 120){
        swap(d[i] , d2[i]) ;
    }
    f(p*2) ;
    rep(i , 0 , sz(B)-1){
        d[i+2] -= B[i] ;
    }
    rep(i , 0 ,sz(A)-1){
        d[i+2] += A[i] ;
    }
    f(p*2+1); 
    rep(i , 0 , 120)d[i] = ls[i] ;
    pr[0] = d[0] ;
    rep(i , 1, 120)pr[i] = pr[i-1] + d[i] ;
    rep(i , 1 , sz(A)-1)A[i] += A[i-1] ;
    rep(i , 1, sz(B)-1)B[i] += B[i-1] ;
    rep(i , 0 , 120){
        if(i ==0){
            ans = (ans + po2((N-1)%(mod-1))-1);
            if(ans > mod)ans-=mod;
            continue ;
        }
        ll t = pr[i] + A[min(sz(A)-1 , i-1)] + B[min(sz(B)-1 , i-1)]+1 ;
        if(t==N)break ;
        ans = (ans + po2((N-t)%(mod-1))-1);
        if(ans > mod)ans -= mod ;
    }
}

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 
    a2[0] = 1;
    rep(i , 1 ,maxn-1){
        a2[i] = (1ll*a2[i-1]*2ll%mod) ;
    }
    rep(k , 0 , 60){
        rep(i , 0 , k){
            rep(d , 0 , 120){
                ll ans = ch(i , d , k) ;
                ll x = i-1 , D = d-1 ;
                while(x!=-1 && D!=-1){
                    ans++ ;
                    ans = (ans + ch(x+1 , D-1 , k));
                    D--;
                    x--;
                }
                dp[k][i][d] = ans ;
            }
        }
    }
    map <ll,ll> mp ;
    int T ;
    cin >> T ;
    while(T--){
        rep(i ,0 , 120)d[i] =0 ;
        ll n;
        cin >> n ;
        if(mp[n]!=0){
            cout << mp[n] << "\n";
            continue ;
        }
        N = n ;
        ans =0 ;
        f();
        mp[n] = ans * po(po(2,n)-1 , mod-2)%mod;
        cout << ans * po(po(2,n)-1 , mod-2)%mod << "\n"; 
    }
    return 0 ;
}
/*


*/
# 결과 실행 시간 메모리 Grader output
1 Correct 556 ms 394084 KB Output is correct
2 Correct 499 ms 394196 KB Output is correct
3 Correct 504 ms 394064 KB Output is correct
4 Correct 497 ms 394136 KB Output is correct
5 Correct 501 ms 394052 KB Output is correct
6 Correct 493 ms 393972 KB Output is correct
7 Correct 495 ms 393968 KB Output is correct
8 Correct 492 ms 394064 KB Output is correct
9 Correct 493 ms 394060 KB Output is correct
10 Correct 499 ms 394144 KB Output is correct
11 Correct 500 ms 394084 KB Output is correct
12 Correct 501 ms 394064 KB Output is correct
13 Correct 497 ms 393952 KB Output is correct
14 Correct 495 ms 394064 KB Output is correct
15 Correct 512 ms 394136 KB Output is correct
16 Correct 523 ms 393976 KB Output is correct
17 Correct 497 ms 394064 KB Output is correct
18 Correct 496 ms 393980 KB Output is correct
19 Correct 494 ms 393944 KB Output is correct
20 Correct 497 ms 394064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 498 ms 394144 KB Output is correct
2 Correct 496 ms 393992 KB Output is correct
3 Correct 498 ms 393932 KB Output is correct
4 Correct 518 ms 394052 KB Output is correct
5 Correct 513 ms 394072 KB Output is correct
6 Correct 503 ms 393960 KB Output is correct
7 Correct 512 ms 393968 KB Output is correct
8 Correct 510 ms 393964 KB Output is correct
9 Correct 519 ms 393976 KB Output is correct
10 Correct 502 ms 394280 KB Output is correct
11 Correct 503 ms 394280 KB Output is correct
12 Correct 503 ms 394344 KB Output is correct
13 Correct 496 ms 394220 KB Output is correct
14 Correct 497 ms 394064 KB Output is correct
15 Correct 499 ms 394304 KB Output is correct
16 Correct 500 ms 393984 KB Output is correct
17 Correct 500 ms 394064 KB Output is correct
18 Correct 497 ms 394188 KB Output is correct
19 Correct 499 ms 394152 KB Output is correct
20 Correct 496 ms 393984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 602 ms 394404 KB Output is correct
2 Correct 615 ms 394348 KB Output is correct
3 Correct 605 ms 394216 KB Output is correct
4 Correct 600 ms 394292 KB Output is correct
5 Correct 535 ms 394376 KB Output is correct
6 Correct 531 ms 394304 KB Output is correct
7 Correct 529 ms 394324 KB Output is correct
8 Correct 530 ms 394324 KB Output is correct
9 Correct 501 ms 393936 KB Output is correct
10 Correct 500 ms 394156 KB Output is correct
11 Correct 502 ms 394056 KB Output is correct
12 Correct 497 ms 393944 KB Output is correct
13 Correct 501 ms 394324 KB Output is correct
14 Correct 503 ms 394408 KB Output is correct
15 Correct 501 ms 394284 KB Output is correct
16 Correct 500 ms 394480 KB Output is correct
17 Correct 507 ms 394352 KB Output is correct
18 Correct 506 ms 394064 KB Output is correct
19 Correct 496 ms 393920 KB Output is correct
20 Correct 499 ms 394068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 556 ms 394084 KB Output is correct
2 Correct 499 ms 394196 KB Output is correct
3 Correct 504 ms 394064 KB Output is correct
4 Correct 497 ms 394136 KB Output is correct
5 Correct 501 ms 394052 KB Output is correct
6 Correct 493 ms 393972 KB Output is correct
7 Correct 495 ms 393968 KB Output is correct
8 Correct 492 ms 394064 KB Output is correct
9 Correct 493 ms 394060 KB Output is correct
10 Correct 499 ms 394144 KB Output is correct
11 Correct 500 ms 394084 KB Output is correct
12 Correct 501 ms 394064 KB Output is correct
13 Correct 497 ms 393952 KB Output is correct
14 Correct 495 ms 394064 KB Output is correct
15 Correct 512 ms 394136 KB Output is correct
16 Correct 523 ms 393976 KB Output is correct
17 Correct 497 ms 394064 KB Output is correct
18 Correct 496 ms 393980 KB Output is correct
19 Correct 494 ms 393944 KB Output is correct
20 Correct 497 ms 394064 KB Output is correct
21 Correct 498 ms 394144 KB Output is correct
22 Correct 496 ms 393992 KB Output is correct
23 Correct 498 ms 393932 KB Output is correct
24 Correct 518 ms 394052 KB Output is correct
25 Correct 513 ms 394072 KB Output is correct
26 Correct 503 ms 393960 KB Output is correct
27 Correct 512 ms 393968 KB Output is correct
28 Correct 510 ms 393964 KB Output is correct
29 Correct 519 ms 393976 KB Output is correct
30 Correct 502 ms 394280 KB Output is correct
31 Correct 503 ms 394280 KB Output is correct
32 Correct 503 ms 394344 KB Output is correct
33 Correct 496 ms 394220 KB Output is correct
34 Correct 497 ms 394064 KB Output is correct
35 Correct 499 ms 394304 KB Output is correct
36 Correct 500 ms 393984 KB Output is correct
37 Correct 500 ms 394064 KB Output is correct
38 Correct 497 ms 394188 KB Output is correct
39 Correct 499 ms 394152 KB Output is correct
40 Correct 496 ms 393984 KB Output is correct
41 Correct 602 ms 394404 KB Output is correct
42 Correct 615 ms 394348 KB Output is correct
43 Correct 605 ms 394216 KB Output is correct
44 Correct 600 ms 394292 KB Output is correct
45 Correct 535 ms 394376 KB Output is correct
46 Correct 531 ms 394304 KB Output is correct
47 Correct 529 ms 394324 KB Output is correct
48 Correct 530 ms 394324 KB Output is correct
49 Correct 501 ms 393936 KB Output is correct
50 Correct 500 ms 394156 KB Output is correct
51 Correct 502 ms 394056 KB Output is correct
52 Correct 497 ms 393944 KB Output is correct
53 Correct 501 ms 394324 KB Output is correct
54 Correct 503 ms 394408 KB Output is correct
55 Correct 501 ms 394284 KB Output is correct
56 Correct 500 ms 394480 KB Output is correct
57 Correct 507 ms 394352 KB Output is correct
58 Correct 506 ms 394064 KB Output is correct
59 Correct 496 ms 393920 KB Output is correct
60 Correct 499 ms 394068 KB Output is correct
61 Correct 498 ms 394128 KB Output is correct
62 Correct 513 ms 394220 KB Output is correct
63 Correct 1569 ms 394760 KB Output is correct
64 Correct 1582 ms 394576 KB Output is correct
65 Correct 1632 ms 394636 KB Output is correct
66 Correct 1583 ms 394832 KB Output is correct
67 Correct 531 ms 394320 KB Output is correct
68 Correct 536 ms 394160 KB Output is correct
69 Correct 556 ms 394340 KB Output is correct
70 Correct 543 ms 394244 KB Output is correct
71 Correct 502 ms 394204 KB Output is correct
72 Correct 509 ms 394056 KB Output is correct
73 Correct 501 ms 394208 KB Output is correct
74 Correct 507 ms 394032 KB Output is correct
75 Correct 506 ms 394292 KB Output is correct
76 Correct 505 ms 394224 KB Output is correct
77 Correct 506 ms 394320 KB Output is correct
78 Correct 504 ms 394260 KB Output is correct
79 Correct 500 ms 393984 KB Output is correct
80 Correct 503 ms 394236 KB Output is correct
81 Correct 500 ms 394200 KB Output is correct
82 Correct 503 ms 394208 KB Output is correct