Submission #949737

# Submission time Handle Problem Language Result Execution time Memory
949737 2024-03-19T15:32:03 Z KiaRez Party (INOI20_party) C++17
63 / 100
3000 ms 15464 KB
/*
    IN THE NAME OF GOD
*/
#include <bits/stdc++.h>

// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;

#define F                                      first
#define S                                      second
#define Mp                                     make_pair
#define pb                                     push_back
#define pf                                     push_front
#define size(x)                                ((ll)x.size())
#define all(x)                                 (x).begin(),(x).end()
#define kill(x)		                           cout << x << '\n', exit(0);
#define fuck(x)                                cout << "(" << #x << " , " << x << ")" << endl
#define endl                                   '\n'

const int N = 3e5+23, lg = 18;
ll Mod = 1e9+7; //998244353;

inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
    ll ans = 1;
    a=MOD(a, mod);
    while (b) {
        if (b & 1) ans = MOD(ans*a, mod);
        b >>= 1;
        a = MOD(a*a, mod);
    }
    return ans;
}

ll q, n, cur, dp[125][125][125], pd[125][125], num[125][125];

ll f(ll m) {
	if(m==0) return 124;
	ll numc=0, now=1, ans=0;
	while(now < m) {
		now*=(2ll); now++; numc++;
	}
	if(now == m) return numc;
	int c1, c2;
	//fuck(m);
	if(m >= (1ll<<numc)+(1ll<<(numc-1ll))) {
		//cout<<(1ll<<(numc))-1<<' '<<(m-(1ll<<numc))<<endl;
		c1=f((1ll<<(numc))-1ll), c2=f(m-(1ll<<(numc)));
	} else {
		//cout<<m-(1ll<<(numc-1))<<' '<<((1ll<<(numc-1)) - 1)<<endl;
		c1=f(m-(1ll<<(numc-1ll))), c2=f((1ll<<(numc-1ll)) - 1ll);
	}
	int i = cur; cur++;
	for(int j=0; j<=60; j++) {
		if(j == 0) num[i][0] = 1;
		else num[i][j] = MOD(num[c1][j-1] + num[c2][j-1]);
		if(j==0) {
			pd[i][j] = MOD(2ll * (pd[c1][0] + 1) * (pd[c2][0] + 1) - 1);
		} else {
			pd[i][j] = MOD((pd[c1][j-1]+1)*(pd[c2][j-1]+1) - 1);
		}
		if(j == 0) {
			for(int k=60; k>0; k--) {
			dp[i][j][k] = MOD((pd[c1][k-1]+1)*(pd[c2][k-1]+1) - (pd[c1][k]+1)*(pd[c2][k]+1));
			}
		} else {
		ll tot1 = (j==0 ? 0 : num[c1][j-1]), tot2 = (j==0 ? 0 : num[c2][j-1]);
		for(int k=2*60; k>0; k--) {
			ll res = 0;
			
			res = MOD(dp[c1][j-1][k] * (j>=k ? (pd[c2][0]+1)*2ll : pd[c2][k-j-1] + 1));
			res = MOD(res + dp[c2][j-1][k] * (j>=k ? (pd[c1][0]+1)*2ll : pd[c1][k-j-1] + 1));

			if(k>=j) res = MOD(res + tot1 * (k==j ? (pd[c2][0]+1) : (pd[c2][k-j-1] - pd[c2][k-j])));
			if(k>=j) res = MOD(res + tot2 * (k==j ? (pd[c1][0]+1) : (pd[c1][k-j-1] - pd[c1][k-j])));
			dp[i][j][k] = res;

			tot1 = MOD(tot1 + dp[c1][j-1][k]);
			tot2 = MOD(tot2 + dp[c2][j-1][k]);
		}
		}
	}
	return i;
}

int main () {
	ios_base::sync_with_stdio(false), cin.tie(0);

	pd[0][0] = 1;
	num[0][0] = 1;
	for(int i=1; i<=60; i++) {
	int c1=i-1, c2=i-1;
	for(int j=0; j<=i; j++) {
		if(j == 0) num[i][0] = 1;
		else num[i][j] = MOD(num[c1][j-1] + num[c2][j-1]);
		if(j==0) {
			pd[i][j] = MOD(2ll * (pd[c1][0] + 1) * (pd[c2][0] + 1) - 1);
		} else {
			pd[i][j] = MOD((pd[c1][j-1]+1)*(pd[c2][j-1]+1) - 1);
		}
		if(j == 0) {
			for(int k=i; k>0; k--) {
			dp[i][j][k] = MOD((pd[c1][k-1]+1)*(pd[c2][k-1]+1) - (pd[c1][k]+1)*(pd[c2][k]+1));
			}
		} else {
		ll tot1 = (j==0 ? 0 : num[c1][j-1]), tot2 = (j==0 ? 0 : num[c2][j-1]);
		for(int k=2*i; k>0; k--) {
			ll res = 0;
			
			res = MOD(dp[c1][j-1][k] * (j>=k ? (pd[c2][0]+1)*2ll : pd[c2][k-j-1] + 1));
			res = MOD(res + dp[c2][j-1][k] * (j>=k ? (pd[c1][0]+1)*2ll : pd[c1][k-j-1] + 1));

			if(k>=j) res = MOD(res + tot1 * (k==j ? (pd[c2][0]+1) : (pd[c2][k-j-1] - pd[c2][k-j])));
			if(k>=j) res = MOD(res + tot2 * (k==j ? (pd[c1][0]+1) : (pd[c1][k-j-1] - pd[c1][k-j])));
			dp[i][j][k] = res;

			tot1 = MOD(tot1 + dp[c1][j-1][k]);
			tot2 = MOD(tot2 + dp[c2][j-1][k]);
		}
		}
	}
	}

	cin>>q;
	while(q--) {
		ll numc=0, now=1, ans=0;
		cin>>n;
		cur = 61;
		ll wh = f(n);
		for(int i=0; i<=60; i++) {
		for(ll j=1; j<=2*60; j++) {
			ans = MOD(ans + j * dp[wh][i][j]);
		}
		}
		for(int i=61; i<=cur; i++) for(int j=0; j<=60; j++) num[i][j]=pd[i][j]=0, fill(dp[i][j], dp[i][j]+2*60, 0);
		//fuck(ans);
		cout<<MOD(ans * poww(poww(2, n)-1, Mod-2))<<endl;
	}

	return 0;
}

Compilation message

Main.cpp: In function 'll f(ll)':
Main.cpp:47:20: warning: unused variable 'ans' [-Wunused-variable]
   47 |  ll numc=0, now=1, ans=0;
      |                    ^~~
Main.cpp: In function 'int main()':
Main.cpp:134:6: warning: unused variable 'numc' [-Wunused-variable]
  134 |   ll numc=0, now=1, ans=0;
      |      ^~~~
Main.cpp:134:14: warning: unused variable 'now' [-Wunused-variable]
  134 |   ll numc=0, now=1, ans=0;
      |              ^~~
# Verdict Execution time Memory Grader output
1 Correct 93 ms 10844 KB Output is correct
2 Correct 102 ms 10588 KB Output is correct
3 Correct 98 ms 10588 KB Output is correct
4 Correct 95 ms 10820 KB Output is correct
5 Correct 153 ms 10840 KB Output is correct
6 Correct 143 ms 10588 KB Output is correct
7 Correct 152 ms 10584 KB Output is correct
8 Correct 154 ms 10844 KB Output is correct
9 Correct 13 ms 8536 KB Output is correct
10 Correct 13 ms 8540 KB Output is correct
11 Correct 74 ms 8796 KB Output is correct
12 Correct 74 ms 8540 KB Output is correct
13 Correct 2145 ms 11076 KB Output is correct
14 Correct 2145 ms 10844 KB Output is correct
15 Correct 2143 ms 10836 KB Output is correct
16 Correct 2144 ms 11080 KB Output is correct
17 Correct 419 ms 9032 KB Output is correct
18 Correct 419 ms 8784 KB Output is correct
19 Correct 422 ms 8776 KB Output is correct
20 Correct 422 ms 8788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 8536 KB Output is correct
2 Correct 13 ms 8540 KB Output is correct
3 Correct 13 ms 8780 KB Output is correct
4 Correct 13 ms 8536 KB Output is correct
5 Correct 13 ms 8788 KB Output is correct
6 Correct 13 ms 8540 KB Output is correct
7 Correct 13 ms 8540 KB Output is correct
8 Correct 13 ms 8724 KB Output is correct
9 Correct 13 ms 8796 KB Output is correct
10 Correct 13 ms 8796 KB Output is correct
11 Correct 82 ms 8784 KB Output is correct
12 Correct 81 ms 8784 KB Output is correct
13 Correct 82 ms 8540 KB Output is correct
14 Correct 81 ms 8796 KB Output is correct
15 Correct 82 ms 8788 KB Output is correct
16 Correct 82 ms 8784 KB Output is correct
17 Correct 81 ms 9040 KB Output is correct
18 Correct 81 ms 8788 KB Output is correct
19 Correct 81 ms 8784 KB Output is correct
20 Correct 81 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1047 ms 14968 KB Output is correct
2 Correct 1092 ms 15184 KB Output is correct
3 Correct 1014 ms 14932 KB Output is correct
4 Correct 1006 ms 15176 KB Output is correct
5 Correct 1144 ms 15244 KB Output is correct
6 Correct 1162 ms 15244 KB Output is correct
7 Correct 1112 ms 15464 KB Output is correct
8 Correct 1163 ms 15384 KB Output is correct
9 Correct 13 ms 8540 KB Output is correct
10 Correct 13 ms 8536 KB Output is correct
11 Correct 13 ms 8788 KB Output is correct
12 Correct 14 ms 8540 KB Output is correct
13 Correct 2309 ms 15188 KB Output is correct
14 Correct 2304 ms 15196 KB Output is correct
15 Correct 2310 ms 15200 KB Output is correct
16 Correct 2328 ms 15196 KB Output is correct
17 Correct 62 ms 8536 KB Output is correct
18 Correct 62 ms 8540 KB Output is correct
19 Correct 62 ms 8540 KB Output is correct
20 Correct 61 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 93 ms 10844 KB Output is correct
2 Correct 102 ms 10588 KB Output is correct
3 Correct 98 ms 10588 KB Output is correct
4 Correct 95 ms 10820 KB Output is correct
5 Correct 153 ms 10840 KB Output is correct
6 Correct 143 ms 10588 KB Output is correct
7 Correct 152 ms 10584 KB Output is correct
8 Correct 154 ms 10844 KB Output is correct
9 Correct 13 ms 8536 KB Output is correct
10 Correct 13 ms 8540 KB Output is correct
11 Correct 74 ms 8796 KB Output is correct
12 Correct 74 ms 8540 KB Output is correct
13 Correct 2145 ms 11076 KB Output is correct
14 Correct 2145 ms 10844 KB Output is correct
15 Correct 2143 ms 10836 KB Output is correct
16 Correct 2144 ms 11080 KB Output is correct
17 Correct 419 ms 9032 KB Output is correct
18 Correct 419 ms 8784 KB Output is correct
19 Correct 422 ms 8776 KB Output is correct
20 Correct 422 ms 8788 KB Output is correct
21 Correct 13 ms 8536 KB Output is correct
22 Correct 13 ms 8540 KB Output is correct
23 Correct 13 ms 8780 KB Output is correct
24 Correct 13 ms 8536 KB Output is correct
25 Correct 13 ms 8788 KB Output is correct
26 Correct 13 ms 8540 KB Output is correct
27 Correct 13 ms 8540 KB Output is correct
28 Correct 13 ms 8724 KB Output is correct
29 Correct 13 ms 8796 KB Output is correct
30 Correct 13 ms 8796 KB Output is correct
31 Correct 82 ms 8784 KB Output is correct
32 Correct 81 ms 8784 KB Output is correct
33 Correct 82 ms 8540 KB Output is correct
34 Correct 81 ms 8796 KB Output is correct
35 Correct 82 ms 8788 KB Output is correct
36 Correct 82 ms 8784 KB Output is correct
37 Correct 81 ms 9040 KB Output is correct
38 Correct 81 ms 8788 KB Output is correct
39 Correct 81 ms 8784 KB Output is correct
40 Correct 81 ms 8540 KB Output is correct
41 Correct 1047 ms 14968 KB Output is correct
42 Correct 1092 ms 15184 KB Output is correct
43 Correct 1014 ms 14932 KB Output is correct
44 Correct 1006 ms 15176 KB Output is correct
45 Correct 1144 ms 15244 KB Output is correct
46 Correct 1162 ms 15244 KB Output is correct
47 Correct 1112 ms 15464 KB Output is correct
48 Correct 1163 ms 15384 KB Output is correct
49 Correct 13 ms 8540 KB Output is correct
50 Correct 13 ms 8536 KB Output is correct
51 Correct 13 ms 8788 KB Output is correct
52 Correct 14 ms 8540 KB Output is correct
53 Correct 2309 ms 15188 KB Output is correct
54 Correct 2304 ms 15196 KB Output is correct
55 Correct 2310 ms 15200 KB Output is correct
56 Correct 2328 ms 15196 KB Output is correct
57 Correct 62 ms 8536 KB Output is correct
58 Correct 62 ms 8540 KB Output is correct
59 Correct 62 ms 8540 KB Output is correct
60 Correct 61 ms 8540 KB Output is correct
61 Correct 6 ms 8536 KB Output is correct
62 Correct 63 ms 15060 KB Output is correct
63 Execution timed out 3038 ms 15188 KB Time limit exceeded
64 Halted 0 ms 0 KB -