結果
問題 | No.2220 Range Insert & Point Mex |
ユーザー | flygon |
提出日時 | 2023-02-17 23:39:33 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,009 ms / 2,000 ms |
コード長 | 1,748 bytes |
コンパイル時間 | 1,342 ms |
コンパイル使用メモリ | 86,884 KB |
実行使用メモリ | 130,416 KB |
最終ジャッジ日時 | 2023-09-28 18:16:21 |
合計ジャッジ時間 | 21,452 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 112 ms
84,800 KB |
testcase_01 | AC | 110 ms
84,892 KB |
testcase_02 | AC | 110 ms
84,888 KB |
testcase_03 | AC | 110 ms
84,868 KB |
testcase_04 | AC | 109 ms
84,864 KB |
testcase_05 | AC | 113 ms
85,000 KB |
testcase_06 | AC | 111 ms
84,780 KB |
testcase_07 | AC | 113 ms
84,952 KB |
testcase_08 | AC | 112 ms
84,824 KB |
testcase_09 | AC | 112 ms
84,880 KB |
testcase_10 | AC | 112 ms
84,812 KB |
testcase_11 | AC | 109 ms
84,896 KB |
testcase_12 | AC | 113 ms
85,044 KB |
testcase_13 | AC | 994 ms
120,884 KB |
testcase_14 | AC | 986 ms
120,732 KB |
testcase_15 | AC | 988 ms
120,812 KB |
testcase_16 | AC | 999 ms
120,592 KB |
testcase_17 | AC | 1,008 ms
120,400 KB |
testcase_18 | AC | 989 ms
120,820 KB |
testcase_19 | AC | 1,009 ms
121,548 KB |
testcase_20 | AC | 503 ms
107,976 KB |
testcase_21 | AC | 498 ms
108,212 KB |
testcase_22 | AC | 496 ms
108,328 KB |
testcase_23 | AC | 452 ms
110,884 KB |
testcase_24 | AC | 431 ms
105,192 KB |
testcase_25 | AC | 372 ms
101,188 KB |
testcase_26 | AC | 335 ms
113,856 KB |
testcase_27 | AC | 291 ms
101,348 KB |
testcase_28 | AC | 154 ms
102,436 KB |
testcase_29 | AC | 214 ms
101,280 KB |
testcase_30 | AC | 154 ms
103,064 KB |
testcase_31 | AC | 445 ms
130,060 KB |
testcase_32 | AC | 382 ms
118,276 KB |
testcase_33 | AC | 392 ms
117,564 KB |
testcase_34 | AC | 696 ms
129,812 KB |
testcase_35 | AC | 712 ms
128,524 KB |
testcase_36 | AC | 701 ms
130,416 KB |
testcase_37 | AC | 715 ms
128,408 KB |
testcase_38 | AC | 424 ms
120,800 KB |
ソースコード
import sys sys.setrecursionlimit(5*10**5) input = sys.stdin.readline from collections import defaultdict, deque, Counter from heapq import heappop, heappush from bisect import bisect_left, bisect_right from math import gcd n= int(input()) lr = [list(map(int,input().split())) for i in range(n)] q = int(input()) x = list(map(int,input().split())) lr.sort(key = lambda x: (x[2], x[0])) lr = lr[::-1] INF= 10**10 seg_len = 1<<19 # > 5*(10**5) seg = [INF]*(2*seg_len) for i in range(q): seg[i+seg_len] = i for i in range(seg_len)[::-1]: seg[i] = min(seg[i*2], seg[i*2+1]) def update(pos): pos += seg_len seg[pos] = INF while True: pos >>= 1 if not pos: break seg[pos] = min(seg[pos<<1], seg[pos<<1|1]) def get_query(l,r): l += seg_len; r += seg_len res = INF while l < r: if l & 1: res = min(res, seg[l]) l += 1 if r & 1: r -= 1 res = min(res, seg[r]) l >>= 1; r >>= 1 return res ans = [-1]*q for num in range(n+10): use = [] mx = 0 while lr and lr[-1][2] == num: l,r,_ = lr.pop() tl = bisect_left(x,l) tr = bisect_right(x,r) mx = max(mx, tr) use.append([tl,1]) use.append([tr,-1]) if not use: break ss = set() now = 0 cnt = 0 use.sort() for i in range(len(use)): pos, cc = use[i] if cnt == 0: tmp = get_query(now, pos) while tmp != INF: update(tmp) ans[tmp] = num tmp = get_query(now, pos) ss.add(tmp) now = pos cnt += cc tmp = get_query(now, seg_len) while tmp != INF: update(tmp) ss.add(tmp) ans[tmp] = num tmp = get_query(now, seg_len) ss.add(tmp) for i in range(q): if ans[i] == -1: ans[i] = num print(*ans, sep = "\n")