結果

問題 No.151 セグメントフィッシング
ユーザー titia
提出日時 2025-10-03 02:57:48
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,654 bytes
コンパイル時間 598 ms
コンパイル使用メモリ 82,480 KB
実行使用メモリ 79,652 KB
最終ジャッジ日時 2025-10-03 02:57:57
合計ジャッジ時間 5,498 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 18 RE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

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 time in range(Q):
    #print([getvalues(i,i+1) for i in range(2*N)])
    com,y,z=input().split()
    y=int(y)
    z=int(z)

    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
        z2=2*N-1-y-(time+1) + 1

        #print(y2,z2)

        if y2<z2:
            ANS+=getvalues(y2,z2)
        else:
            ANS+=getvalues(y2,2*N)+getvalues(0,z2)

        print(ANS)


        
        
        

0