結果
問題 | No.2220 Range Insert & Point Mex |
ユーザー | mkawa2 |
提出日時 | 2023-02-18 00:31:44 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 454 ms / 2,000 ms |
コード長 | 3,263 bytes |
コンパイル時間 | 417 ms |
コンパイル使用メモリ | 82,556 KB |
実行使用メモリ | 212,872 KB |
最終ジャッジ日時 | 2024-07-21 12:56:53 |
合計ジャッジ時間 | 11,783 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 38 ms
56,480 KB |
testcase_01 | AC | 38 ms
56,112 KB |
testcase_02 | AC | 40 ms
56,440 KB |
testcase_03 | AC | 38 ms
55,308 KB |
testcase_04 | AC | 37 ms
55,636 KB |
testcase_05 | AC | 40 ms
55,592 KB |
testcase_06 | AC | 40 ms
56,484 KB |
testcase_07 | AC | 38 ms
55,116 KB |
testcase_08 | AC | 39 ms
55,720 KB |
testcase_09 | AC | 40 ms
55,708 KB |
testcase_10 | AC | 40 ms
56,456 KB |
testcase_11 | AC | 38 ms
55,760 KB |
testcase_12 | AC | 39 ms
56,016 KB |
testcase_13 | AC | 414 ms
212,608 KB |
testcase_14 | AC | 405 ms
212,328 KB |
testcase_15 | AC | 404 ms
212,856 KB |
testcase_16 | AC | 410 ms
212,528 KB |
testcase_17 | AC | 415 ms
212,488 KB |
testcase_18 | AC | 435 ms
212,872 KB |
testcase_19 | AC | 412 ms
212,564 KB |
testcase_20 | AC | 390 ms
204,964 KB |
testcase_21 | AC | 385 ms
204,764 KB |
testcase_22 | AC | 414 ms
205,352 KB |
testcase_23 | AC | 452 ms
148,672 KB |
testcase_24 | AC | 423 ms
134,212 KB |
testcase_25 | AC | 337 ms
138,276 KB |
testcase_26 | AC | 413 ms
157,348 KB |
testcase_27 | AC | 247 ms
112,044 KB |
testcase_28 | AC | 143 ms
137,964 KB |
testcase_29 | AC | 148 ms
121,240 KB |
testcase_30 | AC | 134 ms
121,188 KB |
testcase_31 | AC | 221 ms
126,000 KB |
testcase_32 | AC | 199 ms
143,080 KB |
testcase_33 | AC | 261 ms
138,952 KB |
testcase_34 | AC | 328 ms
171,060 KB |
testcase_35 | AC | 403 ms
169,788 KB |
testcase_36 | AC | 280 ms
151,364 KB |
testcase_37 | AC | 350 ms
151,012 KB |
testcase_38 | AC | 454 ms
175,368 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = (1 << 63)-1 # inf = (1 << 31)-1 # md = 10**9+7 md = 998244353 from collections import defaultdict class DualSegTree: def __init__(self, op, e, v): self._op = op self._e = e() if isinstance(v, int): v = [self._e]*v self._n = len(v) self._log = (self._n-1).bit_length() self._size = 1 << self._log self._d = [self._e]*(2*self._size) for i in range(self._n): self._d[self._size+i] = v[i] def apply(self, left, right, f): assert 0 <= left <= right <= self._n if left == right: return left += self._size right += self._size for i in range(self._log, 0, -1): if ((left >> i) << i) != left: self._push(left >> i) if ((right >> i) << i) != right: self._push((right-1) >> i) while left < right: if left & 1: self._d[left] = self._op(self._d[left], f) left += 1 if right & 1: right -= 1 self._d[right] = self._op(self._d[right], f) left >>= 1 right >>= 1 def get(self, p): assert 0 <= p < self._n p += self._size res = self._e while p: res = self._op(res, self._d[p]) p >>= 1 return res def all_array(self): res = [] for i in range(self._n): res.append(self.get(i)) return res def _push(self, k): self._d[k*2] = self._op(self._d[k*2], self._d[k]) self._d[k*2+1] = self._op(self._d[k*2+1], self._d[k]) self._d[k] = self._e def e():return inf n=II() alr=defaultdict(list) dec=set([0]) mx=0 for _ in range(n): l,r,a=LI() r+=1 alr[a].append((l,r)) dec.add(l) dec.add(r) mx=max(mx,r) q=II() xx=LI() mx=max(mx,xx[-1]) dec.add(mx+1) dec|=set(xx) dec=sorted(dec) enc={a:i for i,a in enumerate(dec)} aa=sorted(alr) for i,a in enumerate(aa): if i!=a:break alr[a].sort(key=lambda x:x[0]) L=R=-1 cur=[(0,0)] for l,r in alr[a]: if L==-1: L,R=l,r elif R<l: cur.append((L,R)) L,R=l,r elif r>R: R=r cur.append((L,R)) cur.append((mx+1,mx+1)) alr[a]=cur m=len(dec) st=DualSegTree(min,e,m) last=-1 for i,a in enumerate(aa): if i!=a:break last=a pr=-1 for l,r in alr[a]: l,r=enc[l],enc[r] if pr>-1:st.apply(pr,l,a) pr=r for x in xx: x=enc[x] ans=st.get(x) if ans==inf:ans=last+1 print(ans)