結果

問題 No.945 YKC饅頭
ユーザー prd_xxxprd_xxx
提出日時 2019-12-08 01:00:07
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 1,266 ms / 2,000 ms
コード長 2,153 bytes
コンパイル時間 1,131 ms
コンパイル使用メモリ 86,920 KB
実行使用メモリ 141,952 KB
最終ジャッジ日時 2023-08-27 14:21:42
合計ジャッジ時間 35,038 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,032 KB
testcase_01 AC 67 ms
71,188 KB
testcase_02 AC 87 ms
76,224 KB
testcase_03 AC 119 ms
77,536 KB
testcase_04 AC 79 ms
76,080 KB
testcase_05 AC 106 ms
76,772 KB
testcase_06 AC 117 ms
77,160 KB
testcase_07 AC 111 ms
77,344 KB
testcase_08 AC 84 ms
76,280 KB
testcase_09 AC 101 ms
77,188 KB
testcase_10 AC 114 ms
77,260 KB
testcase_11 AC 105 ms
77,032 KB
testcase_12 AC 111 ms
77,584 KB
testcase_13 AC 120 ms
77,264 KB
testcase_14 AC 121 ms
77,504 KB
testcase_15 AC 85 ms
76,492 KB
testcase_16 AC 88 ms
75,972 KB
testcase_17 AC 105 ms
76,728 KB
testcase_18 AC 112 ms
77,180 KB
testcase_19 AC 88 ms
76,324 KB
testcase_20 AC 82 ms
76,332 KB
testcase_21 AC 86 ms
75,968 KB
testcase_22 AC 138 ms
77,376 KB
testcase_23 AC 118 ms
77,308 KB
testcase_24 AC 120 ms
77,228 KB
testcase_25 AC 117 ms
77,476 KB
testcase_26 AC 122 ms
77,136 KB
testcase_27 AC 79 ms
76,124 KB
testcase_28 AC 83 ms
76,284 KB
testcase_29 AC 64 ms
71,132 KB
testcase_30 AC 64 ms
70,992 KB
testcase_31 AC 211 ms
82,216 KB
testcase_32 AC 264 ms
82,880 KB
testcase_33 AC 456 ms
97,100 KB
testcase_34 AC 701 ms
114,440 KB
testcase_35 AC 1,093 ms
137,600 KB
testcase_36 AC 656 ms
123,996 KB
testcase_37 AC 657 ms
122,460 KB
testcase_38 AC 681 ms
117,300 KB
testcase_39 AC 321 ms
89,020 KB
testcase_40 AC 384 ms
91,468 KB
testcase_41 AC 256 ms
83,904 KB
testcase_42 AC 925 ms
129,280 KB
testcase_43 AC 554 ms
123,504 KB
testcase_44 AC 858 ms
124,616 KB
testcase_45 AC 958 ms
140,880 KB
testcase_46 AC 208 ms
82,864 KB
testcase_47 AC 740 ms
113,556 KB
testcase_48 AC 267 ms
86,640 KB
testcase_49 AC 423 ms
93,940 KB
testcase_50 AC 1,023 ms
141,952 KB
testcase_51 AC 1,248 ms
141,368 KB
testcase_52 AC 1,263 ms
141,468 KB
testcase_53 AC 1,266 ms
141,492 KB
testcase_54 AC 1,262 ms
141,588 KB
testcase_55 AC 1,254 ms
141,508 KB
testcase_56 AC 282 ms
85,644 KB
testcase_57 AC 276 ms
85,524 KB
testcase_58 AC 818 ms
126,824 KB
testcase_59 AC 893 ms
135,456 KB
testcase_60 AC 518 ms
102,264 KB
testcase_61 AC 839 ms
128,960 KB
testcase_62 AC 818 ms
127,620 KB
testcase_63 AC 323 ms
86,900 KB
testcase_64 AC 587 ms
104,288 KB
testcase_65 AC 528 ms
100,332 KB
testcase_66 AC 522 ms
99,448 KB
testcase_67 AC 728 ms
114,788 KB
testcase_68 AC 563 ms
102,664 KB
testcase_69 AC 396 ms
91,224 KB
testcase_70 AC 444 ms
93,088 KB
testcase_71 AC 431 ms
92,652 KB
testcase_72 AC 672 ms
108,756 KB
testcase_73 AC 891 ms
128,716 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
N,M = map(int,input().split())
LRT = [input().split() for i in range(M)]

#参照
#https://smijake3.hatenablog.com/entry/2018/11/03/100133

INF = 2**31-1

LV = N.bit_length()
N0 = 2**LV
data = [INF]*(2*N0)
lazy = [None]*(2*N0)

# 伝搬される区間のインデックス(1-indexed)を全て列挙するgenerator
LV = (N-1).bit_length()
N0 = 2**LV
def gindex(l, r):
    L = l + N0; R = r + N0
    lm = (L // (L & -L)) >> 1
    rm = (R // (R & -R)) >> 1
    while L < R:
        if R <= rm:
            yield R
        if L <= lm:
            yield L
        L >>= 1; R >>= 1
    while L:
        yield L
        L >>= 1

# 1-indexedで単調増加のインデックスリストを渡す
def propagates(*ids):
    for i in reversed(ids):
        v = lazy[i-1]
        if v is None:
            continue
        lazy[2*i-1] = data[2*i-1] = lazy[2*i] = data[2*i] = v
        lazy[i-1] = None

def update(l, r, x):
    *ids, = gindex(l, r)
    # 1. トップダウンにlazyの値を伝搬
    propagates(*ids)

    # 2. 区間[l, r)のdata, lazyの値を更新
    L = N0 + l; R = N0 + r
    while L < R:
        if R & 1:
            R -= 1
            lazy[R-1] = data[R-1] = x
        if L & 1:
            lazy[L-1] = data[L-1] = x
            L += 1
        L >>= 1; R >>= 1

    # 3. 伝搬させた区間について、ボトムアップにdataの値を伝搬する
    for i in ids:
        data[i-1] = min(data[2*i-1], data[2*i])

def query(l, r):
    # 1. トップダウンにlazyの値を伝搬
    propagates(*gindex(l, r))
    L = N0 + l; R = N0 + r

    # 2. 区間[l, r)の最小値を求める
    s = INF
    while L < R:
        if R & 1:
            R -= 1
            s = min(s, data[R-1])
        if L & 1:
            s = min(s, data[L-1])
            L += 1
        L >>= 1; R >>= 1
    return s



for i,(l,r,t) in reversed(list(enumerate(LRT))):
    l,r = int(l),int(r)
    update(l,r+1,i)

y = k = c = 0
for i in range(1,N+1):
    j = query(i,i+1)
    if j >= M: continue
    t = LRT[j][2]
    if t=='Y':
        y += 1
    elif t=='K':
        k += 1
    else:
        c += 1
print(y,k,c)
0