Submission #949730

# Submission time Handle Problem Language Result Execution time Memory
949730 2024-03-19T15:30:10 Z KiaRez Party (INOI20_party) C++17
63 / 100
3000 ms 15264 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 95 ms 10844 KB Output is correct
2 Correct 104 ms 10844 KB Output is correct
3 Correct 98 ms 10844 KB Output is correct
4 Correct 95 ms 10844 KB Output is correct
5 Correct 154 ms 10844 KB Output is correct
6 Correct 145 ms 10848 KB Output is correct
7 Correct 154 ms 10844 KB Output is correct
8 Correct 155 ms 10840 KB Output is correct
9 Correct 13 ms 8536 KB Output is correct
10 Correct 13 ms 8792 KB Output is correct
11 Correct 78 ms 8800 KB Output is correct
12 Correct 78 ms 8792 KB Output is correct
13 Correct 2166 ms 10852 KB Output is correct
14 Correct 2163 ms 11092 KB Output is correct
15 Correct 2162 ms 11100 KB Output is correct
16 Correct 2172 ms 11092 KB Output is correct
17 Correct 428 ms 8792 KB Output is correct
18 Correct 427 ms 8796 KB Output is correct
19 Correct 427 ms 8796 KB Output is correct
20 Correct 432 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 8796 KB Output is correct
2 Correct 13 ms 8796 KB Output is correct
3 Correct 14 ms 8796 KB Output is correct
4 Correct 14 ms 8792 KB Output is correct
5 Correct 14 ms 8800 KB Output is correct
6 Correct 14 ms 8800 KB Output is correct
7 Correct 14 ms 8796 KB Output is correct
8 Correct 13 ms 8796 KB Output is correct
9 Correct 14 ms 9016 KB Output is correct
10 Correct 14 ms 8796 KB Output is correct
11 Correct 85 ms 8828 KB Output is correct
12 Correct 86 ms 8828 KB Output is correct
13 Correct 88 ms 8828 KB Output is correct
14 Correct 86 ms 8828 KB Output is correct
15 Correct 86 ms 8828 KB Output is correct
16 Correct 84 ms 8828 KB Output is correct
17 Correct 89 ms 8816 KB Output is correct
18 Correct 84 ms 8828 KB Output is correct
19 Correct 85 ms 8828 KB Output is correct
20 Correct 90 ms 8948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1063 ms 15120 KB Output is correct
2 Correct 1097 ms 15184 KB Output is correct
3 Correct 1030 ms 15120 KB Output is correct
4 Correct 1034 ms 15208 KB Output is correct
5 Correct 1161 ms 15264 KB Output is correct
6 Correct 1219 ms 15252 KB Output is correct
7 Correct 1155 ms 15248 KB Output is correct
8 Correct 1226 ms 15248 KB Output is correct
9 Correct 14 ms 8780 KB Output is correct
10 Correct 14 ms 8796 KB Output is correct
11 Correct 14 ms 8804 KB Output is correct
12 Correct 15 ms 8796 KB Output is correct
13 Correct 2392 ms 15184 KB Output is correct
14 Correct 2382 ms 15188 KB Output is correct
15 Correct 2382 ms 15184 KB Output is correct
16 Correct 2351 ms 15184 KB Output is correct
17 Correct 62 ms 8540 KB Output is correct
18 Correct 62 ms 8792 KB Output is correct
19 Correct 62 ms 8540 KB Output is correct
20 Correct 63 ms 8792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 95 ms 10844 KB Output is correct
2 Correct 104 ms 10844 KB Output is correct
3 Correct 98 ms 10844 KB Output is correct
4 Correct 95 ms 10844 KB Output is correct
5 Correct 154 ms 10844 KB Output is correct
6 Correct 145 ms 10848 KB Output is correct
7 Correct 154 ms 10844 KB Output is correct
8 Correct 155 ms 10840 KB Output is correct
9 Correct 13 ms 8536 KB Output is correct
10 Correct 13 ms 8792 KB Output is correct
11 Correct 78 ms 8800 KB Output is correct
12 Correct 78 ms 8792 KB Output is correct
13 Correct 2166 ms 10852 KB Output is correct
14 Correct 2163 ms 11092 KB Output is correct
15 Correct 2162 ms 11100 KB Output is correct
16 Correct 2172 ms 11092 KB Output is correct
17 Correct 428 ms 8792 KB Output is correct
18 Correct 427 ms 8796 KB Output is correct
19 Correct 427 ms 8796 KB Output is correct
20 Correct 432 ms 8796 KB Output is correct
21 Correct 13 ms 8796 KB Output is correct
22 Correct 13 ms 8796 KB Output is correct
23 Correct 14 ms 8796 KB Output is correct
24 Correct 14 ms 8792 KB Output is correct
25 Correct 14 ms 8800 KB Output is correct
26 Correct 14 ms 8800 KB Output is correct
27 Correct 14 ms 8796 KB Output is correct
28 Correct 13 ms 8796 KB Output is correct
29 Correct 14 ms 9016 KB Output is correct
30 Correct 14 ms 8796 KB Output is correct
31 Correct 85 ms 8828 KB Output is correct
32 Correct 86 ms 8828 KB Output is correct
33 Correct 88 ms 8828 KB Output is correct
34 Correct 86 ms 8828 KB Output is correct
35 Correct 86 ms 8828 KB Output is correct
36 Correct 84 ms 8828 KB Output is correct
37 Correct 89 ms 8816 KB Output is correct
38 Correct 84 ms 8828 KB Output is correct
39 Correct 85 ms 8828 KB Output is correct
40 Correct 90 ms 8948 KB Output is correct
41 Correct 1063 ms 15120 KB Output is correct
42 Correct 1097 ms 15184 KB Output is correct
43 Correct 1030 ms 15120 KB Output is correct
44 Correct 1034 ms 15208 KB Output is correct
45 Correct 1161 ms 15264 KB Output is correct
46 Correct 1219 ms 15252 KB Output is correct
47 Correct 1155 ms 15248 KB Output is correct
48 Correct 1226 ms 15248 KB Output is correct
49 Correct 14 ms 8780 KB Output is correct
50 Correct 14 ms 8796 KB Output is correct
51 Correct 14 ms 8804 KB Output is correct
52 Correct 15 ms 8796 KB Output is correct
53 Correct 2392 ms 15184 KB Output is correct
54 Correct 2382 ms 15188 KB Output is correct
55 Correct 2382 ms 15184 KB Output is correct
56 Correct 2351 ms 15184 KB Output is correct
57 Correct 62 ms 8540 KB Output is correct
58 Correct 62 ms 8792 KB Output is correct
59 Correct 62 ms 8540 KB Output is correct
60 Correct 63 ms 8792 KB Output is correct
61 Correct 7 ms 8796 KB Output is correct
62 Correct 63 ms 14928 KB Output is correct
63 Execution timed out 3027 ms 15200 KB Time limit exceeded
64 Halted 0 ms 0 KB -