結果
問題 |
No.2220 Range Insert & Point Mex
|
ユーザー |
![]() |
提出日時 | 2025-04-15 23:27:34 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 1,507 bytes |
コンパイル時間 | 292 ms |
コンパイル使用メモリ | 82,352 KB |
実行使用メモリ | 178,624 KB |
最終ジャッジ日時 | 2025-04-15 23:29:14 |
合計ジャッジ時間 | 22,306 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 35 TLE * 1 |
ソースコード
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)) # Add event events.append((r + 1, 0, a)) # Remove event Q = int(input[ptr]) ptr += 1 x_list = list(map(int, input[ptr:ptr+Q])) ptr += Q for idx, x in enumerate(x_list): events.append((x, 2, idx)) # Query event (type 2) # Sort events by position, then by type (0 < 1 < 2) events.sort(key=lambda x: (x[0], x[1])) count = defaultdict(int) active = set() mex = 0 ans = [0] * Q for event in events: pos, typ, val = event if typ == 0: # Remove event a = val count[a] -= 1 if count[a] == 0: if a in active: active.remove(a) if a < mex: mex = min(mex, a) elif typ == 1: # Add event a = val count[a] += 1 if count[a] == 1: active.add(a) if a == mex: while mex in active: mex += 1 else: # Query event idx = val ans[idx] = mex for num in ans: print(num) if __name__ == '__main__': main()