結果

問題 No.3112 区間和係数多項式?
ユーザー ShirotsumeShirotsume
提出日時 2024-03-04 15:30:27
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,331 bytes
コンパイル時間 379 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 184,464 KB
最終ジャッジ日時 2024-03-04 15:31:08
合計ジャッジ時間 38,668 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
60,264 KB
testcase_01 AC 34 ms
53,460 KB
testcase_02 AC 35 ms
53,460 KB
testcase_03 AC 35 ms
53,460 KB
testcase_04 AC 35 ms
53,460 KB
testcase_05 AC 34 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 35 ms
53,460 KB
testcase_10 AC 36 ms
53,460 KB
testcase_11 AC 38 ms
53,460 KB
testcase_12 AC 43 ms
61,452 KB
testcase_13 AC 80 ms
75,440 KB
testcase_14 AC 85 ms
76,044 KB
testcase_15 AC 135 ms
76,900 KB
testcase_16 AC 3,956 ms
159,212 KB
testcase_17 AC 3,357 ms
159,212 KB
testcase_18 AC 3,456 ms
162,300 KB
testcase_19 AC 3,595 ms
159,212 KB
testcase_20 AC 3,790 ms
159,212 KB
testcase_21 AC 3,326 ms
159,212 KB
testcase_22 AC 2,792 ms
159,212 KB
testcase_23 AC 3,649 ms
159,212 KB
testcase_24 TLE -
testcase_25 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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 sum0(self,r):
        s=0
        while(r>0):
            s+=self.data[r-1]
            r-=r&-r
        return s
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())

a = [c1]

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

def p(x):
    # the number of trailing zeros
    #x: int
    X = x
    if x==0:
        return 0
    res=0
    while(x%2==0):
        x//=2
        res+=1
    
    return X - 2 ** res
P = [p(i) for i in range(n + 1)]
    
def f(j, y):
    if j == 0:
        return a[0] % b
    else:
        return (y * f(P[j], y) + A.sum(P[j] + 1, j + 1)) % b
    
i, j, x, y = c2%n, c3%n, c4%b, c5%b
for _ in range(q):
    A.add(i, x - a[i])
    a[i] = x
    print(f(j, y))
    i *= d2
    i %= n
    j *= d3
    j %= n
    x *= d4
    x %= b
    y *= d5
    y %= b
    
0