結果

問題 No.3112 区間和係数多項式?
ユーザー ShirotsumeShirotsume
提出日時 2024-03-12 23:51:08
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 4,754 ms / 6,000 ms
コード長 1,493 bytes
コンパイル時間 259 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 399,960 KB
最終ジャッジ日時 2024-03-12 23:52:06
合計ジャッジ時間 57,152 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 36 ms
53,460 KB
testcase_02 AC 36 ms
53,460 KB
testcase_03 AC 35 ms
53,460 KB
testcase_04 AC 35 ms
53,460 KB
testcase_05 AC 36 ms
53,460 KB
testcase_06 AC 35 ms
53,460 KB
testcase_07 AC 35 ms
53,460 KB
testcase_08 AC 36 ms
53,460 KB
testcase_09 AC 37 ms
53,460 KB
testcase_10 AC 37 ms
53,460 KB
testcase_11 AC 37 ms
53,460 KB
testcase_12 AC 46 ms
61,580 KB
testcase_13 AC 55 ms
66,372 KB
testcase_14 AC 69 ms
76,044 KB
testcase_15 AC 71 ms
76,044 KB
testcase_16 AC 4,332 ms
394,200 KB
testcase_17 AC 3,852 ms
395,736 KB
testcase_18 AC 4,754 ms
395,480 KB
testcase_19 AC 3,888 ms
395,864 KB
testcase_20 AC 3,996 ms
394,968 KB
testcase_21 AC 4,671 ms
395,864 KB
testcase_22 AC 3,857 ms
393,560 KB
testcase_23 AC 4,268 ms
395,096 KB
testcase_24 AC 4,251 ms
399,960 KB
testcase_25 AC 4,289 ms
399,832 KB
testcase_26 AC 2,696 ms
392,408 KB
testcase_27 AC 2,690 ms
392,408 KB
testcase_28 AC 2,419 ms
391,640 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n, b, q = map(int, input().split())
c1, d1 = map(int, input().split())
c2, d2 = map(int, input().split())
c3, d3 = map(int, input().split())
c4, d4 = map(int, input().split())
c5, d5 = map(int, input().split())

class fenwick_tree():
    n=1
    data=[0 for i in range(n)]
    def __init__(self,N):
        self.n=N
        self.data=[0 for i in range(N)]
    def add(self,p,x):
        p+=1
        while(p<=self.n):
            self.data[p-1]+=x
            p+=p& -p
    def sum(self,l,r):
        return self.sum0(r)-self.sum0(l)
    def sump(self,r):
        
        return self.data[r - 1]
    def sum0(self,r):
        s=0
        while(r>0):
            s+=self.data[r-1]
            r-=r&-r
        return s

a = [c1]

for i in range(n - 1):
    a.append(a[-1] * d1 % b)
A = fenwick_tree(n)
B = fenwick_tree(n)
for i in range(1,n):
    A.add(i - 1, a[i])

def p(x):
    # the number of trailing zeros
    #x: int
    X = x
    if x==0:
        return 0
    res=0
    v = 1
    while(x%2==0):
        x//=2
        res+=1
        v *= 2
    return X - v
P = [p(i) for i in range(n + 1)]

i, j, x, y = c2 % n, c3 % n, c4 % b, c5 % b
ans = 0
for _ in range(q):
    
    if i >= 1:
        A.add(i - 1, x - a[i])
    a[i] = x
    ans = 0
    yy = 1
    jj = j
    while jj:
        ans += A.sump(jj) * yy
        jj = P[jj]
        yy *= y
        yy %= b
    ans += yy * a[0]
    print(ans % b)
    i *= d2
    i %= n
    j *= d3
    j %= n
    x *= d4
    x %= b
    y *= d5
    y %= b
0