結果

問題 No.2220 Range Insert & Point Mex
ユーザー lam6er
提出日時 2025-04-15 23:27:54
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,320 bytes
コンパイル時間 215 ms
コンパイル使用メモリ 82,180 KB
実行使用メモリ 159,856 KB
最終ジャッジ日時 2025-04-15 23:29:24
合計ジャッジ時間 18,637 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 35 TLE * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import defaultdict

def main():
    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, 1, a))
        events.append((r + 1, -1, a))
    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

    e = 0
    count = defaultdict(int)
    present = set()
    mex = 0

    for x in x_list:
        while e < len(events):
            pos, typ, a = events[e]
            if pos > x:
                break
            if typ == 1:
                if a >= 0:
                    count[a] += 1
                    if count[a] == 1:
                        present.add(a)
                        while mex in present:
                            mex += 1
            else:
                if a >= 0:
                    count[a] -= 1
                    if count[a] == 0:
                        if a in present:
                            present.remove(a)
                            if a < mex:
                                mex = a
            e += 1
        print(mex)

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