結果
| 問題 |
No.2220 Range Insert & Point Mex
|
| コンテスト | |
| ユーザー |
gew1fw
|
| 提出日時 | 2025-06-12 16:48:16 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,449 bytes |
| コンパイル時間 | 293 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 156,920 KB |
| 最終ジャッジ日時 | 2025-06-12 16:49:17 |
| 合計ジャッジ時間 | 18,168 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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
# Sort events by x, then by type (0 before 1)
events.sort(key=lambda x: (x[0], x[1]))
q = int(input[ptr])
ptr += 1
xs = list(map(int, input[ptr:ptr+q]))
ptr += q
active = defaultdict(int)
mex = 0
ans = []
event_ptr = 0
for x in xs:
# Process all events with x_event <= x
while event_ptr < len(events) and events[event_ptr][0] <= x:
x_event, typ, a = events[event_ptr]
if typ == 1:
# Add event
active[a] += 1
if a == mex:
# Increment mex until not found
while mex in active:
mex += 1
else:
# Remove event
if active[a] == 1:
del active[a]
if a < mex:
mex = min(mex, a)
else:
active[a] -= 1
event_ptr += 1
ans.append(mex)
print('\n'.join(map(str, ans)))
if __name__ == "__main__":
main()
gew1fw