結果
| 問題 |
No.8112 区間和係数多項式?
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-03-04 15:13:50 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,493 bytes |
| コンパイル時間 | 310 ms |
| コンパイル使用メモリ | 82,288 KB |
| 実行使用メモリ | 363,688 KB |
| 最終ジャッジ日時 | 2024-09-29 17:21:49 |
| 合計ジャッジ時間 | 13,194 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 15 RE * 1 TLE * 1 -- * 12 |
ソースコード
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):
assert 0<=p<self.n,"0<=p<n,p={0},n={1}".format(p,self.n)
p+=1
while(p<=self.n):
self.data[p-1]+=x
p+=p& -p
def sum(self,l,r):
assert (0<=l and l<=r and r<=self.n),"0<=l<=r<=n,l={0},r={1},n={2}".format(l,r,self.n)
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):
#caluculate 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, c3, c4, c5
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