結果

問題 No.2220 Range Insert & Point Mex
ユーザー gew1fw
提出日時 2025-06-12 20:14:27
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,480 bytes
コンパイル時間 358 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 153,380 KB
最終ジャッジ日時 2025-06-12 20:17:43
合計ジャッジ時間 20,392 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

def main():
    import sys
    input = sys.stdin.read().split()
    ptr = 0
    N = int(input[ptr])
    ptr += 1

    events = []
    for _ in range(N):
        l = int(input[ptr])
        r = int(input[ptr+1])
        a = int(input[ptr+2])
        ptr +=3
        events.append((l, 0, a))
        events.append((r + 1, 1, a))

    # Sort events by pos, then add before remove (type 0 before 1)
    events.sort(key=lambda x: (x[0], x[1]))

    Q = int(input[ptr])
    ptr +=1
    x_list = list(map(int, input[ptr:ptr+Q]))
    ptr += Q

    current_mex = 0
    count = dict()
    e_ptr = 0
    result = []

    for x in x_list:
        while e_ptr < len(events) and events[e_ptr][0] <= x:
            pos, typ, a = events[e_ptr]
            if typ == 0:
                # Add event
                if a in count:
                    count[a] += 1
                else:
                    count[a] = 1
                    # Check if current_mex is affected
                    while current_mex in count:
                        current_mex += 1
            else:
                # Remove event
                if a in count:
                    count[a] -= 1
                    if count[a] == 0:
                        del count[a]
                        if a < current_mex:
                            current_mex = min(current_mex, a)
            e_ptr += 1
        result.append(current_mex)
    
    print('\n'.join(map(str, result)))

if __name__ == '__main__':
    main()
0