結果
| 問題 |
No.259 セグメントフィッシング+
|
| コンテスト | |
| ユーザー |
titia
|
| 提出日時 | 2025-10-31 23:27:29 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 298 ms / 2,000 ms |
| コード長 | 1,691 bytes |
| コンパイル時間 | 562 ms |
| コンパイル使用メモリ | 82,292 KB |
| 実行使用メモリ | 86,964 KB |
| 最終ジャッジ日時 | 2025-10-31 23:27:37 |
| 合計ジャッジ時間 | 7,664 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 23 |
ソースコード
import sys
input = sys.stdin.readline
N,Q=map(int,input().split())
def seg_function(x,y): # Segment treeで扱うfunction
return x+y
seg_el=1<<((2*N+5).bit_length()) # Segment treeの台の要素数
SEG=[0]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化
def update(n,x,seg_el): # A[n]を+x更新
i=n+seg_el
SEG[i]+=x
i>>=1 # 子ノードへ
while i!=0:
SEG[i]=seg_function(SEG[i*2],SEG[i*2+1])
i>>=1
def getvalues(l,r): # 区間[l,r)に関するseg_functionを調べる
L=l+seg_el
R=r+seg_el
ANS1=0
ANS2=0
while L<R:
if L & 1:
ANS1=seg_function(ANS1, SEG[L])
L+=1
if R & 1:
R-=1
ANS2=seg_function(SEG[R], ANS2)
L>>=1
R>>=1
return seg_function(ANS1, ANS2)
for t in range(Q):
#print([getvalues(i,i+1) for i in range(2*N)])
com,time,y,z=input().split()
y=int(y)
z=int(z)
time=int(time)
if com=="R":
update((y-(time+1))%(2*N),z,seg_el)
elif com=="L":
now=2*N-1-y
update((now-(time+1))%(2*N),z,seg_el)
else:
#print([getvalues(i,i+1) for i in range(2*N)])
y1=(y-(time+1))%(2*N)
z1=(z-(time+1))%(2*N)
#print(y1,z1)
if y1<z1:
ANS=getvalues(y1,z1)
else:
ANS=getvalues(y1,2*N)+getvalues(0,z1)
y2=(2*N-1-z-(time+1) + 1)%(2*N)
z2=(2*N-1-y-(time+1) + 1)%(2*N)
#print(y2,z2)
if y2<z2:
ANS+=getvalues(y2,z2)
else:
ANS+=getvalues(y2,2*N)+getvalues(0,z2)
print(ANS)
titia