結果

問題 No.945 YKC饅頭
ユーザー titiatitia
提出日時 2019-12-08 01:46:58
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,202 ms / 2,000 ms
コード長 2,727 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 87,172 KB
実行使用メモリ 128,900 KB
最終ジャッジ日時 2023-08-27 14:57:58
合計ジャッジ時間 35,735 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,036 KB
testcase_01 AC 72 ms
71,296 KB
testcase_02 AC 102 ms
76,124 KB
testcase_03 AC 118 ms
77,196 KB
testcase_04 AC 85 ms
76,032 KB
testcase_05 AC 111 ms
76,988 KB
testcase_06 AC 121 ms
76,948 KB
testcase_07 AC 113 ms
76,920 KB
testcase_08 AC 90 ms
76,176 KB
testcase_09 AC 105 ms
76,360 KB
testcase_10 AC 116 ms
77,308 KB
testcase_11 AC 104 ms
76,260 KB
testcase_12 AC 118 ms
76,932 KB
testcase_13 AC 121 ms
77,544 KB
testcase_14 AC 118 ms
77,096 KB
testcase_15 AC 89 ms
76,072 KB
testcase_16 AC 97 ms
76,248 KB
testcase_17 AC 112 ms
76,980 KB
testcase_18 AC 114 ms
76,940 KB
testcase_19 AC 95 ms
76,116 KB
testcase_20 AC 92 ms
76,232 KB
testcase_21 AC 91 ms
76,444 KB
testcase_22 AC 124 ms
77,500 KB
testcase_23 AC 128 ms
77,392 KB
testcase_24 AC 127 ms
77,372 KB
testcase_25 AC 126 ms
77,088 KB
testcase_26 AC 126 ms
77,352 KB
testcase_27 AC 95 ms
76,236 KB
testcase_28 AC 103 ms
76,896 KB
testcase_29 AC 71 ms
71,388 KB
testcase_30 AC 73 ms
71,228 KB
testcase_31 AC 280 ms
83,196 KB
testcase_32 AC 355 ms
83,116 KB
testcase_33 AC 575 ms
96,144 KB
testcase_34 AC 629 ms
105,576 KB
testcase_35 AC 1,025 ms
121,972 KB
testcase_36 AC 641 ms
112,232 KB
testcase_37 AC 663 ms
108,980 KB
testcase_38 AC 652 ms
106,948 KB
testcase_39 AC 394 ms
87,716 KB
testcase_40 AC 458 ms
91,732 KB
testcase_41 AC 331 ms
84,916 KB
testcase_42 AC 837 ms
116,044 KB
testcase_43 AC 534 ms
108,964 KB
testcase_44 AC 820 ms
113,516 KB
testcase_45 AC 885 ms
120,392 KB
testcase_46 AC 222 ms
83,908 KB
testcase_47 AC 695 ms
104,344 KB
testcase_48 AC 279 ms
84,592 KB
testcase_49 AC 447 ms
92,364 KB
testcase_50 AC 975 ms
121,956 KB
testcase_51 AC 1,159 ms
128,388 KB
testcase_52 AC 1,125 ms
127,564 KB
testcase_53 AC 1,178 ms
127,796 KB
testcase_54 AC 1,141 ms
128,420 KB
testcase_55 AC 1,202 ms
128,900 KB
testcase_56 AC 293 ms
87,144 KB
testcase_57 AC 445 ms
86,864 KB
testcase_58 AC 723 ms
114,100 KB
testcase_59 AC 780 ms
120,316 KB
testcase_60 AC 557 ms
99,752 KB
testcase_61 AC 744 ms
116,676 KB
testcase_62 AC 738 ms
114,264 KB
testcase_63 AC 477 ms
87,624 KB
testcase_64 AC 577 ms
100,000 KB
testcase_65 AC 556 ms
97,488 KB
testcase_66 AC 542 ms
96,720 KB
testcase_67 AC 644 ms
107,568 KB
testcase_68 AC 572 ms
99,812 KB
testcase_69 AC 511 ms
91,352 KB
testcase_70 AC 506 ms
91,928 KB
testcase_71 AC 508 ms
92,672 KB
testcase_72 AC 610 ms
103,604 KB
testcase_73 AC 770 ms
118,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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


seg_el=1<<(N.bit_length()) # Segment treeの台の要素数
seg_height=1+N.bit_length() # Segment treeの高さ
SEG=[0]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化
LAZY=[None]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化

def indexes(L,R): # 遅延伝搬すべきノードのリストを返す. (つまり, updateやgetvaluesで見るノードより上にあるノードたち)
    INDLIST=[]

    R-=1
    
    L>>=1
    R>>=1

    while L!=R:
        if L>R:
            INDLIST.append(L)
            L>>=1
        else:
            INDLIST.append(R)
            R>>=1

    while L!=0:
        INDLIST.append(L)
        L>>=1

    return INDLIST

def updates(l,r,x): # 区間[l,r)をxに更新
        
    L=l+seg_el
    R=r+seg_el

    L//=(L & (-L))
    R//=(R & (-R))

    UPIND=indexes(L,R)
    
    for ind in UPIND[::-1]: # 遅延伝搬
        if LAZY[ind]!=None:
            update_lazy = LAZY[ind] *(1<<(seg_height - 1 - (ind.bit_length())))
            LAZY[ind<<1]=LAZY[1+(ind<<1)]=LAZY[ind]
            SEG[ind<<1]=SEG[1+(ind<<1)]=update_lazy
            LAZY[ind]=None

    while L!=R:
        if L > R:
            SEG[L]=x * (1<<(seg_height - (L.bit_length())))
            LAZY[L]=x
            L+=1
            L//=(L & (-L))

        else:
            R-=1
            SEG[R]=x * (1<<(seg_height - (R.bit_length())))
            LAZY[R]=x
            R//=(R & (-R))

    for ind in UPIND:
        SEG[ind]=SEG[ind<<1]+SEG[1+(ind<<1)]

def getvalues(l,r): # 区間[l,r)に関する和を調べる

    L=l+seg_el
    R=r+seg_el

    L//=(L & (-L))
    R//=(R & (-R))

    UPIND=indexes(L,R)
    
    for ind in UPIND[::-1]: # 遅延伝搬
        if LAZY[ind]!=None:
            update_lazy = LAZY[ind] *(1<<(seg_height - 1 - (ind.bit_length())))
            LAZY[ind<<1]=LAZY[1+(ind<<1)]=LAZY[ind]
            SEG[ind<<1]=SEG[1+(ind<<1)]=update_lazy
            LAZY[ind]=None
            
    ANS=0

    while L!=R:
        if L > R:
            ANS+=SEG[L]
            L+=1
            L//=(L & (-L))

        else:
            R-=1
            ANS+=SEG[R]
            R//=(R & (-R))

    return ANS

QLIST=[list(input().split()) for i in range(M)]

for L,R,T in QLIST[::-1]:
    L=int(L)
    R=int(R)
    if T=="Y":
        updates(L,R+1,1)
    elif T=="K":
        updates(L,R+1,2)
    else:
        updates(L,R+1,3)

ANSY=0
ANSK=0
ANSC=0

for i in range(1,N+1):
    #print(getvalues(i,i+1))
    if getvalues(i,i+1)==1:
        ANSY+=1
    elif getvalues(i,i+1)==2:
        ANSK+=1
    elif getvalues(i,i+1)==3:
        ANSC+=1

print(ANSY,ANSK,ANSC)
        
        
        
0