結果

問題 No.2220 Range Insert & Point Mex
ユーザー lam6er
提出日時 2025-04-15 23:22:46
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,538 bytes
コンパイル時間 216 ms
コンパイル使用メモリ 82,208 KB
実行使用メモリ 152,164 KB
最終ジャッジ日時 2025-04-15 23:24:29
合計ジャッジ時間 16,474 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
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))  # add event
        events.append((r + 1, 1, a))  # remove event

    # Sort events: by position, then add events (0) before remove events (1)
    events.sort()

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

    # Initialize variables
    count = {}
    m = 0
    event_ptr = 0
    res = []

    for x in queries:
        # Process all events with pos <= x
        while event_ptr < len(events) and events[event_ptr][0] <= x:
            pos, typ, a = events[event_ptr]
            if typ == 0:
                # Add event
                if a in count:
                    count[a] += 1
                else:
                    count[a] = 1
                    # Check if current m is affected
                    while m in count:
                        m += 1
            else:
                # Remove event
                if a in count:
                    if count[a] == 1:
                        del count[a]
                        if a < m:
                            m = min(m, a)
                    else:
                        count[a] -= 1
            event_ptr += 1
        res.append(m)

    for num in res:
        print(num)

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