QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#136954#241. Chiaki Sequence Revisitedckz100 ✓158ms3480kbC++202.1kb2023-08-09 14:45:142023-08-09 14:45:18

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-08-09 14:45:18]
  • 评测
  • 测评结果:100
  • 用时:158ms
  • 内存:3480kb
  • [2023-08-09 14:45:14]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define all(a) (a).begin(),(a).end()
using namespace std;

#define int ll
const int mod = 1e9 + 7;
const int N = 2e5 + 10;

ll get(ll n)
{
	ll x=(1ll<<62);
    // cerr << x << "\n";
	ll sum=0;
	while (n && x>=1)
	{
		if (n>=(x-1)) 
		{
			n=n-(x-1);
			sum+=x/2;
		}
		x=x/2;
	}
	return sum;
}

int Num[100];

ll qpow(ll base, ll pow)
{
    ll res = 1;
    while(pow)
    {
        if(pow & 1) res = res * base % mod;
        pow >>= 1;
        base = base * base % mod;
    }
    return res;
}

void add(int &a, int b){
    a = (a + b) % mod;
}
int cntt=0;
int pw2[100];
void solve()
{
    cntt++;
	ll n;
	cin >> n;

    // if (cntt==10001) cout << n << "\n";
    ll mx=get(n-2) + 1;
	int x = mx;
	int len = 0;
	while(mx)
	{
		Num[++len] = mx % 2;
		mx /= 2;	
	}
	
    // cerr << x << '\n';//1100
	int ans = 0;
    int res = 0;
    int inv2 = qpow(2, mod - 2);
	for(int i = len; i >= 1; i--)
    {
        res = res * 2 + Num[i];
        int tmp = res;
        // cerr << tmp << "\n";
        int sum;
        tmp=res%mod;
        if(res % 2){
            sum = (1 + tmp) % mod * (1 + tmp) % mod * inv2 % mod * inv2 % mod;
            // cout << 1+res << "\n";
        }
        else{
            tmp--;
            tmp=(tmp+mod)%mod;
            sum = (1 + tmp) % mod * (1 + tmp) % mod * inv2 % mod * inv2 % mod;
            // cout << 1+tmp << "\n";
        }
        sum = sum * pw2[i - 1] % mod;
        // cerr << i <<" " << ans << " " << sum <<" " << pw2[i-1] << "\n";
        add(ans, sum * i % mod);
    }
	
	int p = n + 1;
    int xx=x%mod;
	while(get(p - 2) + 1 == x)
	{

		ans = (ans - xx + mod) % mod;
        // cerr << ans << " " << x <<  "\n";
		p++;
	}
	cout << (ans + 1) % mod << '\n';
}

signed main()
{
	
    ios::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);
    int t = 1;
    pw2[0] = 1;
    for(int i = 1; i < 100; i++) pw2[i] = pw2[i - 1] * 2 % mod;
    cin >> t; 
    while(t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 158ms
memory: 3480kb

input:

100000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
1...

output:

1
2
4
6
9
13
17
21
26
32
38
45
53
61
69
77
86
96
106
117
129
141
153
166
180
194
209
225
241
257
273
289
306
324
342
361
381
401
421
442
464
486
509
533
557
581
605
630
656
682
709
737
765
793
822
852
882
913
945
977
1009
1041
1073
1105
1138
1172
1206
1241
1277
1313
1349
1386
1424
1462
1501
1541
158...

result:

ok 100000 lines