QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#184315#6793. Chiaki Sequenceucup-team004#AC ✓2111ms91468kbPython32.1kb2023-09-20 16:46:502023-09-20 16:46:51

Judging History

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

  • [2023-09-20 16:46:51]
  • 评测
  • 测评结果:AC
  • 用时:2111ms
  • 内存:91468kb
  • [2023-09-20 16:46:50]
  • 提交

answer

a = [1, 2]
s = {1}
v = 1
K = 700
pre = [0]
for i in range(2, K) :
    if i % 2 == 0 :
        a.append(a[i - 1] * 2)
    else :
        while v in s :
            v += 1
        a.append(a[i - 1] + v)
        # print(v)
    for j in range(i) :
        s.add(a[i] - a[j])
P = 10 ** 9 + 7
pre = [0]
for i in range(K) :
    pre.append((pre[i] + a[i]) % P)
# print(a[len(a) - 1])
# print(10 ** 100)

s = list(s)
s.sort()
# print(s)

seg = []

for i in range(1, len(s)) :
    if s[i] > s[i - 1] + 1 :
        seg.append((s[i - 1] + 1, s[i]))

inv2 = pow(2, P - 2, P)

def calc(n) :
    return 2 * pow(inv2, n % (P - 1), P) * (P - n % P - 1 + pow(2, n % (P - 1), P)) % P

m = len(seg)
while seg[m - 1][0] > 10 ** 101 :
    seg.pop()
    m -= 1
pre1 = [0]
pre2 = [0]
cnt = [0]

for i in range(m) :
    (l, r) = seg[i]
    t = cnt[i]
    s1 = (r - l) * (l + r - 1) // 2 * (P - 3) % P
    s2 = calc(r - l) * pow(inv2, t % (P - 1), P) % P
    s2 = (s2 + l * 2 * (1 - pow(inv2, (r - l) % (P - 1), P) + P) * pow(inv2, t % (P - 1), P)) % P
    pre1.append((pre1[i] + s1) % P)
    pre2.append((pre2[i] + s2) % P)
    cnt.append(cnt[i] + r - l)

T = int(input())
for _ in range(T) :
    n = int(input())
    if n <= K :
        print(pre[n])
    else :
        v = (n - K) // 2
        s1 = pre[K]
        s2 = a[K - 1] * 4 % P
        s1 = (s1 + a[K - 1] * (P - 4)) % P
        if n % 2 == 1 :
            s2 = (s2 + a[K - 1] * 2) % P
        lo = 0
        hi = m - 1
        while lo < hi :
            x = (lo + hi + 1) // 2
            if cnt[x] <= v :
                lo = x;
            else :
                hi = x - 1
        s1 = (s1 + pre1[lo]) % P
        s2 = (s2 + pre2[lo] * (2 + n % 2)) % P
        t = cnt[lo]
        (l, r) = seg[lo]
        r = l + v - t
        s1 = (s1 + (r - l) * (l + r - 1) // 2 * (P - 3)) % P
        s2 = (s2 + calc(r - l) * pow(inv2, t, P) * (2 + n % 2)) % P
        s2 = (s2 + l * 2 * (1 - pow(inv2, r - l, P) + P) * pow(inv2, t, P) * (2 + n % 2)) % P
        ans = (s1 + s2 * pow(2, v, P)) % P
        print(ans)

詳細信息

Test #1:

score: 100
Accepted
time: 2086ms
memory: 91468kb

input:

11
1
2
3
4
5
6
7
8
9
10
1000000000

output:

1
3
7
15
31
52
94
145
247
359
834069170

result:

ok 11 lines

Test #2:

score: 0
Accepted
time: 2111ms
memory: 91448kb

input:

1000
822981260158260522
28316250877914575
779547116602436426
578223540024979445
335408917861648772
74859962623690081
252509054433933447
760713016476190629
919845426262703497
585335723211047202
522842184971407775
148049062628894325
84324828731963982
354979173822804784
1312150450968417
269587449430302...

output:

402022187
461557706
192243935
823942920
825501319
5661468
745813676
94702210
711442549
154526807
393243809
290927990
514237755
235285820
334619351
449545285
182465559
618080214
987942678
381954645
191695479
477442291
234477766
62692133
478109339
898101048
334537080
97017450
777256759
79451012
294963...

result:

ok 1000 lines