結果
| 問題 | No.3492 区間冪乗加算一点取得 |
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2026-04-16 01:17:00 |
| 言語 | PyPy3 (7.3.17) |
| 結果 |
AC
|
| 実行時間 | 1,489 ms / 4,000 ms |
| コード長 | 2,040 bytes |
| 記録 | |
| コンパイル時間 | 161 ms |
| コンパイル使用メモリ | 85,120 KB |
| 実行使用メモリ | 508,196 KB |
| 最終ジャッジ日時 | 2026-04-16 01:17:19 |
| 合計ジャッジ時間 | 19,082 ms |
|
ジャッジサーバーID (参考情報) |
judge2_1 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 27 |
ソースコード
import sys
input = sys.stdin.readline
# class化
class Bit_indexed_tree():
def __init__(self, LEN):
self.BIT = [0]*(LEN+1) # 1-indexedなtree. 配列BITの長さはLEN+1にしていることに注意。
self.LEN = LEN
def update(self,v,w): # index vにwを加える
while v<=self.LEN:
self.BIT[v]+=w
v+=(v&(-v)) # v&(-v)で、最も下の立っているビット. 自分を含む大きなノードへ. たとえばv=3→v=4
def getvalue(self,v): # [1,v]の区間の和を求める
if v==0:
return 0
ANS=0
while v!=0:
ANS+=self.BIT[v]
ANS%=mod
v-=(v&(-v)) # 自分より小さい自分の和を構成するノードへ. たとえばv=14→v=12へ
return ANS%mod
def bisect_on_BIT(self,x): # [1,ind]の和がはじめてx以上になるindexを探す
if x<=0:
return 0
ANS=0
h=1<<((self.LEN).bit_length()-1) # LEN以下の最小の2ベキ
while h>0:
if ANS+h<=self.LEN and self.BIT[ANS+h]<x:
x-=self.BIT[ANS+h]
ANS+=h
h//=2
return ANS+1 # LENまでの和がx未満のとき, LEN+1を返すことに注意
N,mod,Q=list(map(int,input().split()))
Combi=[[] for i in range(N+1)]
Combi[0]=[1,0]
for i in range(1,N+1):
Combi[i].append(1)
for j in range(i):
Combi[i].append((Combi[i-1][j]+Combi[i-1][j+1])%mod)
Combi[i].append(0)
DP=[Bit_indexed_tree(N+3) for i in range(100+2)]
for tests in range(Q):
#print([DP[0].getvalue(i) for i in range(N)])
#print([DP[1].getvalue(i) for i in range(N)])
L,M,R,C,D=list(map(int,input().split()))
for i in range(D+1):
#print(C,D,i,Combi[D][i],pow(C,D-i,mod))
DP[i].update(L,Combi[D][i]*pow(C,D-i,mod)%mod)
DP[i].update(R+1,-Combi[D][i]*pow(C,D-i,mod)%mod)
ANS=0
for i in range(101):
ANS+=DP[i].getvalue(M)*pow(M,i,mod)
ANS%=mod
print(ANS)
titia