QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#136839#241. Chiaki Sequence Revisitedwhsyhyyh#0 0ms0kbC++141.7kb2023-08-09 12:37:222023-08-09 12:37:26

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 12:37:26]
  • 评测
  • 测评结果:0
  • 用时:0ms
  • 内存:0kb
  • [2023-08-09 12:37:22]
  • 提交

answer

#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define LL long long
#define mod 1000000007
#define fi first
#define se second
#define PLL pair<LL,LL>
#define mkp make_pair
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define drep(i,r,l) for(int i=r;i>=l;i--)
using namespace std;
LL rd() {
	LL res=0,f=1;char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-') f*=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') res=(res<<1)+(res<<3)+(ch^48),ch=getchar();
	return res*f;
}
unordered_map<LL,int>MP;
map<LL,PLL>mp;
LL hight_bit(LL x)
{
    x= x|(x>>1);
    x= x|(x>>2);
    x= x|(x>>4);
    x= x|(x>>8);
    x= x|(x>>16);
    x= x|(x>>32);
    return (x+1) >> 1;
}
PLL G[10000010];
PLL solve(LL n) {
	if(n==0) return mkp(0,0);
	if(n==1) return mkp(1,1);
	if(n<=10000000&&G[n].fi!=0) return G[n];
	if(mp.count(n)) return mp[n];
	LL tmp=hight_bit(n),cnt=MP[tmp];
	
	if(tmp*2==n) {
		PLL C=solve(tmp-1);
		return mkp((C.fi*2+cnt*2+3)%mod,(C.se*2+n%mod*(cnt+2)+tmp%mod*(cnt+1)+tmp%mod*C.fi)%mod);
	}
	PLL A=solve(tmp-1),B=solve(n-tmp);
	if(n<=10000000) return G[n]=mkp((A.fi+B.fi+cnt+1)%mod,(A.se+tmp%mod*B.fi+tmp%mod*(cnt+1)+B.se)%mod);
	return mp[n]=mkp((A.fi+B.fi+cnt+1)%mod,(A.se+tmp%mod*B.fi+tmp%mod*(cnt+1)+B.se)%mod);
}
int T;
LL n;
int main() {
	LL x=1;
	rep(i,1,62) x*=2,MP[x]=i;
	T=rd();
	while(T--) {
		n=rd();
		LL l=0,now=n-1;
		drep(i,60,0) if((1ll<<(i+1))-1<=now) l+=1ll<<i,now-=(1ll<<(i+1))-1;
		PLL tmp=solve(l); 
		printf("%lld\n",(1+tmp.se+(l+1)%mod*(n%mod-1-tmp.fi+mod)%mod)%mod);
	}
	return 0;
}

详细

Test #1:

score: 0
Time Limit Exceeded

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: