結果

問題 No.2992 Range ABCD String Query
ユーザー titiatitia
提出日時 2024-12-17 07:27:34
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,006 bytes
コンパイル時間 369 ms
コンパイル使用メモリ 82,368 KB
実行使用メモリ 538,600 KB
最終ジャッジ日時 2024-12-17 07:31:01
合計ジャッジ時間 199,553 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 900 ms
353,368 KB
testcase_01 AC 1,095 ms
91,956 KB
testcase_02 AC 1,481 ms
354,336 KB
testcase_03 AC 998 ms
353,796 KB
testcase_04 AC 1,271 ms
355,016 KB
testcase_05 AC 955 ms
354,340 KB
testcase_06 AC 1,174 ms
340,612 KB
testcase_07 AC 522 ms
352,232 KB
testcase_08 AC 1,360 ms
356,352 KB
testcase_09 AC 916 ms
355,080 KB
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 MLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 AC 5,953 ms
269,456 KB
testcase_21 TLE -
testcase_22 TLE -
testcase_23 TLE -
testcase_24 TLE -
testcase_25 TLE -
testcase_26 TLE -
testcase_27 TLE -
testcase_28 TLE -
testcase_29 TLE -
testcase_30 TLE -
testcase_31 TLE -
testcase_32 TLE -
testcase_33 TLE -
testcase_34 TLE -
testcase_35 TLE -
testcase_36 TLE -
testcase_37 AC 391 ms
83,564 KB
testcase_38 AC 468 ms
83,780 KB
testcase_39 AC 526 ms
83,964 KB
testcase_40 AC 621 ms
288,116 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N,Q=map(int,input().split())

C=[[0,0],[0,1],[0,2],[0,3],[1,1],[1,2],[1,3],[2,2],[2,3],[3,3]]
AA=[(0, 0), (0, 1), (0, 2), (0, 3), (0, 4), (0, 5), (0, 6), (0, 7), (0, 8), (0, 9), (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9), (2, 7), (2, 8), (2, 9), (3, 9), (4, 4), (4, 5), (4, 6), (4, 7), (4, 8), (4, 9), (5, 7), (5, 8), (5, 9), (6, 9), (7, 7), (7, 8), (7, 9), (8, 9), (9, 9)]
LIST=[[-1]*4 for i in range(4)]

for i in range(len(C)):
    x,y=C[i]
    LIST[x][y]=i
    
def seg_function(x,y): # Segment treeで扱うfunction
    #print(x,y)
    ANS=[1<<30]*10

    for i,j in AA:
        a,b=C[i]
        c,d=C[j]

        if b<=c:
            k=LIST[a][d]
            ANS[k]=min(ANS[k],x[i]+y[j])
    return ANS
                

seg_el=1<<(N.bit_length()) # Segment treeの台の要素数
SEG=[[1<<30]*10 for i in range(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]*10
    ANS2=[0]*10

    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)

S=input().strip()
AX=[]

for i in range(4):
    X=[1]*10
    for j in range(i+1):
        for k in range(i,4):
            X[LIST[j][k]]=0

    #print(X)
    AX.append(X)

for i in range(len(S)):
    update(i,AX[ord(S[i])-65],seg_el)

LANS=[]
for tests in range(Q):
    x,y,z=input().split()

    if int(x)==1:
        y=int(y)-1

        update(y,AX[ord(z)-65],seg_el)
    else:
        ANS=getvalues(int(y)-1,int(z))
        LANS.append(ANS[3])

print("\n".join(map(str,LANS)))
        
0