# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
623321 |
2022-08-05T12:49:07 Z |
Arinoor |
Party (INOI20_party) |
C++17 |
|
3000 ms |
7200 KB |
#include <bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define bug(x) cout << #x << " : " << x << '\n'
typedef long long ll;
typedef pair<int, int> pii;
const int maxn = 61;
const int mod = 1e9 + 7;
const int inf = 1e9 + 10;
ll n, lg;
ll dp[maxn << 1][maxn][maxn], pd[maxn << 1][maxn][maxn];
inline int add(int a, int b){
int c = a + b;
if(c >= mod) c -= mod;
return c;
}
inline int neg(int a, int b){
int c = a - b;
if(c < 0) c += mod;
return c;
}
inline int mul(int a, int b){
return 1ll * a * b % mod;
}
inline int pwr(int a, int b){
int res = 1;
for(; b; b >>= 1, a = mul(a, a)) if(b & 1) res = mul(res, a);
return res;
}
inline bool check(int h, int H){
if(h > lg)
return false;
if(h < lg or H == lg)
return true;
return n >> (lg - (H + 1)) & 1;
}
inline int get_cnt(int h, int H){
if(h > lg)
return 0;
if(h < lg or H == lg)
return pwr(2, max(0, h - H - 1));
if(!check(h, H))
return 0;
return pwr(2, h - H - 1);
}
int main(){
ios;
int q; cin >> q;
while(q--){
cin >> n;
if(n == 1){
cout << "0\n";
continue;
}
lg = 63 - __builtin_clzll(n);
for(int h = 0; h <= lg; h ++){
for(int H = 0; H <= h; H ++){
dp[0][h][H] = pd[0][h][H] = check(h, H);
if(H < h){
pd[1][h][H] = 2 * check(h + 1, H);
dp[1][h][H] = pd[1][h][H] + 1;
}
else{
pd[1][h][H] = check(h + 1, H) + check(h + 1, H + 1);
dp[1][h][H] = pd[1][h][H] + (h > 0);
}
}
}
for(int i = 0; i <= 1; i ++){
memset(dp[i][lg + 1], 0, sizeof dp[i][lg + 1]);
memset(pd[i][lg + 1], 0, sizeof pd[i][lg + 1]);
}
for(int l = 2; l <= lg * 2; l ++){
for(int h = 0; h <= lg; h ++){
for(int H = 0; H <= h; H ++){
ll &r1 = pd[l][h][H];
ll &r2 = dp[l][h][H];
if(H < h){
r1 = 2 * pd[l - 1][h + 1][H];
r2 = r1 + dp[l - 1][h - 1][H];
r2 = r2 - pd[l - 2][h][H];
}
else{
r2 = r1 = pd[l - 1][h + 1][H + 1] + pd[l - 1][h + 1][H];
if(h){
r2 = r2 + dp[l - 1][h - 1][H - 1];
r2 = r2 - pd[l - 2][h][H];
}
}
}
}
memset(dp[l][lg + 1], 0, sizeof dp[l][lg + 1]);
memset(pd[l][lg + 1], 0, sizeof pd[l][lg + 1]);
}
int ans = 0;
for(int h = 0; h <= lg; h ++){
for(int H = 0; H <= h; H ++){
int res = 0;
ll sum = 0;
for(int l = 0; l <= 2 * lg; l ++){
sum += dp[l][h][H];
int res2 = neg(pwr(2, dp[l][h][H] % (mod - 1)), 1);
res2 = mul(res2, pwr(2, (n - sum) % (mod - 1)));
res = add(res, mul(res2, l));
}
ans = add(ans, mul(res, get_cnt(h, H)));
}
}
int inv = pwr(neg(pwr(2, n % (mod - 1)), 1), mod - 2);
cout << mul(ans, inv) << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
3 ms |
468 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
43 ms |
536 KB |
Output is correct |
12 |
Correct |
40 ms |
536 KB |
Output is correct |
13 |
Correct |
44 ms |
524 KB |
Output is correct |
14 |
Correct |
44 ms |
528 KB |
Output is correct |
15 |
Correct |
41 ms |
528 KB |
Output is correct |
16 |
Correct |
45 ms |
540 KB |
Output is correct |
17 |
Correct |
39 ms |
536 KB |
Output is correct |
18 |
Correct |
36 ms |
536 KB |
Output is correct |
19 |
Correct |
40 ms |
536 KB |
Output is correct |
20 |
Correct |
35 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2572 ms |
7124 KB |
Output is correct |
2 |
Correct |
2994 ms |
7128 KB |
Output is correct |
3 |
Correct |
2658 ms |
7124 KB |
Output is correct |
4 |
Correct |
2418 ms |
7128 KB |
Output is correct |
5 |
Correct |
2719 ms |
7132 KB |
Output is correct |
6 |
Correct |
2565 ms |
7132 KB |
Output is correct |
7 |
Correct |
2401 ms |
7120 KB |
Output is correct |
8 |
Correct |
2603 ms |
7128 KB |
Output is correct |
9 |
Correct |
2426 ms |
7128 KB |
Output is correct |
10 |
Correct |
2668 ms |
7008 KB |
Output is correct |
11 |
Execution timed out |
3060 ms |
7124 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2473 ms |
7128 KB |
Output is correct |
2 |
Correct |
2801 ms |
7132 KB |
Output is correct |
3 |
Correct |
2496 ms |
7128 KB |
Output is correct |
4 |
Correct |
2515 ms |
7132 KB |
Output is correct |
5 |
Execution timed out |
3088 ms |
7200 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
2 ms |
468 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
2 ms |
468 KB |
Output is correct |
5 |
Correct |
3 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
468 KB |
Output is correct |
7 |
Correct |
3 ms |
468 KB |
Output is correct |
8 |
Correct |
3 ms |
468 KB |
Output is correct |
9 |
Correct |
1 ms |
468 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
43 ms |
536 KB |
Output is correct |
12 |
Correct |
40 ms |
536 KB |
Output is correct |
13 |
Correct |
44 ms |
524 KB |
Output is correct |
14 |
Correct |
44 ms |
528 KB |
Output is correct |
15 |
Correct |
41 ms |
528 KB |
Output is correct |
16 |
Correct |
45 ms |
540 KB |
Output is correct |
17 |
Correct |
39 ms |
536 KB |
Output is correct |
18 |
Correct |
36 ms |
536 KB |
Output is correct |
19 |
Correct |
40 ms |
536 KB |
Output is correct |
20 |
Correct |
35 ms |
468 KB |
Output is correct |
21 |
Correct |
2572 ms |
7124 KB |
Output is correct |
22 |
Correct |
2994 ms |
7128 KB |
Output is correct |
23 |
Correct |
2658 ms |
7124 KB |
Output is correct |
24 |
Correct |
2418 ms |
7128 KB |
Output is correct |
25 |
Correct |
2719 ms |
7132 KB |
Output is correct |
26 |
Correct |
2565 ms |
7132 KB |
Output is correct |
27 |
Correct |
2401 ms |
7120 KB |
Output is correct |
28 |
Correct |
2603 ms |
7128 KB |
Output is correct |
29 |
Correct |
2426 ms |
7128 KB |
Output is correct |
30 |
Correct |
2668 ms |
7008 KB |
Output is correct |
31 |
Execution timed out |
3060 ms |
7124 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |