結果
問題 | No.2421 entersys? |
ユーザー | とりゐ |
提出日時 | 2023-08-12 13:48:18 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,266 ms / 3,000 ms |
コード長 | 7,478 bytes |
コンパイル時間 | 295 ms |
コンパイル使用メモリ | 82,384 KB |
実行使用メモリ | 258,624 KB |
最終ジャッジ日時 | 2024-11-19 16:15:39 |
合計ジャッジ時間 | 22,567 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 63 ms
68,468 KB |
testcase_01 | AC | 81 ms
78,360 KB |
testcase_02 | AC | 100 ms
78,584 KB |
testcase_03 | AC | 67 ms
72,312 KB |
testcase_04 | AC | 82 ms
78,152 KB |
testcase_05 | AC | 97 ms
79,016 KB |
testcase_06 | AC | 98 ms
79,084 KB |
testcase_07 | AC | 95 ms
79,096 KB |
testcase_08 | AC | 99 ms
78,936 KB |
testcase_09 | AC | 112 ms
78,580 KB |
testcase_10 | AC | 94 ms
78,828 KB |
testcase_11 | AC | 1,009 ms
211,024 KB |
testcase_12 | AC | 978 ms
202,168 KB |
testcase_13 | AC | 991 ms
203,056 KB |
testcase_14 | AC | 978 ms
194,504 KB |
testcase_15 | AC | 1,004 ms
194,220 KB |
testcase_16 | AC | 999 ms
199,132 KB |
testcase_17 | AC | 1,010 ms
202,776 KB |
testcase_18 | AC | 1,086 ms
196,400 KB |
testcase_19 | AC | 1,075 ms
202,896 KB |
testcase_20 | AC | 1,076 ms
198,700 KB |
testcase_21 | AC | 798 ms
183,080 KB |
testcase_22 | AC | 849 ms
218,608 KB |
testcase_23 | AC | 1,266 ms
258,624 KB |
testcase_24 | AC | 1,229 ms
258,308 KB |
testcase_25 | AC | 1,241 ms
258,020 KB |
testcase_26 | AC | 680 ms
171,560 KB |
testcase_27 | AC | 693 ms
170,984 KB |
testcase_28 | AC | 699 ms
172,484 KB |
ソースコード
from sys import stdin input=lambda :stdin.readline()[:-1] class segtree(): def __init__(self,init,func,ide): self.n=len(init) self.func=func self.ide=ide self.size=1<<(self.n-1).bit_length() self.tree=[self.ide for i in range(2*self.size)] for i in range(self.n): self.tree[self.size+i]=init[i] for i in range(self.size-1,0,-1): self.tree[i]=self.func(self.tree[2*i], self.tree[2*i|1]) def update(self,k,x): k+=self.size self.tree[k]=x k>>=1 while k: self.tree[k]=self.func(self.tree[2*k],self.tree[k*2|1]) k>>=1 def get(self,i): return self.tree[i+self.size] def query(self,l,r): l+=self.size r+=self.size l_res=self.ide r_res=self.ide while l<r: if l&1: l_res=self.func(l_res,self.tree[l]) l+=1 if r&1: r-=1 r_res=self.func(self.tree[r],r_res) l>>=1 r>>=1 return self.func(l_res,r_res) def max_right(self,l,f): assert 0<=l<=self.n assert f(self.ide) if l==self.n: return self.n l+=self.size res=self.ide while True: while l&1==0: l>>=1 if not f(self.func(res,self.tree[l])): while l<self.size: l*=2 if f(self.func(res,self.tree[l])): res=self.func(res,self.tree[l]) l+=1 return l-self.size res=self.func(res,self.tree[l]) l+=1 if l&(-l)==l: break return self.n def min_left(self,r,f): assert 0<=r<=self.n assert f(self.ide) if r==0: return 0 r+=self.size res=self.ide while True: r-=1 while r>1 and r&1: r>>=1 if not f(self.func(self.tree[r],res)): while r<self.size: r=2*r+1 if f(self.func(self.tree[r],res)): res=self.func(self.tree[r],res) r-=1 return r+1-self.size res=self.func(self.tree[r],res) if r&(-r)==r: break return 0 def __getitem__(self,i): return self.get(i) def __setitem__(self,key,val): self.update(key,val) def __iter__(self): for i in range(self.n): yield self.tree[i+self.size] def __str__(self): return str(list(self)) import math from bisect import bisect_left, bisect_right from typing import Generic, Iterable, Iterator, TypeVar, Union, List T = TypeVar('T') class SortedSet(Generic[T]): BUCKET_RATIO = 50 REBUILD_RATIO = 170 def _build(self, a=None) -> None: "Evenly divide `a` into buckets." if a is None: a = list(self) size = self.size = len(a) bucket_size = int(math.ceil(math.sqrt(size / self.BUCKET_RATIO))) self.a = [a[size * i // bucket_size : size * (i + 1) // bucket_size] for i in range(bucket_size)] def __init__(self, a: Iterable[T] = []) -> None: "Make a new SortedSet from iterable. / O(N) if sorted and unique / O(N log N)" a = list(a) if not all(a[i] < a[i + 1] for i in range(len(a) - 1)): a = sorted(set(a)) self._build(a) def __iter__(self) -> Iterator[T]: for i in self.a: for j in i: yield j def __reversed__(self) -> Iterator[T]: for i in reversed(self.a): for j in reversed(i): yield j def __len__(self) -> int: return self.size def __repr__(self) -> str: return "SortedSet" + str(self.a) def __str__(self) -> str: s = str(list(self)) return "{" + s[1 : len(s) - 1] + "}" def _find_bucket(self, x: T) -> List[T]: "Find the bucket which should contain x. self must not be empty." for a in self.a: if x <= a[-1]: return a return a def __contains__(self, x: T) -> bool: if self.size == 0: return False a = self._find_bucket(x) i = bisect_left(a, x) return i != len(a) and a[i] == x def add(self, x: T) -> bool: "Add an element and return True if added. / O(√N)" if self.size == 0: self.a = [[x]] self.size = 1 return True a = self._find_bucket(x) i = bisect_left(a, x) if i != len(a) and a[i] == x: return False a.insert(i, x) self.size += 1 if len(a) > len(self.a) * self.REBUILD_RATIO: self._build() return True def discard(self, x: T) -> bool: "Remove an element and return True if removed. / O(√N)" if self.size == 0: return False a = self._find_bucket(x) i = bisect_left(a, x) if i == len(a) or a[i] != x: return False a.pop(i) self.size -= 1 if len(a) == 0: self._build() return True def lt(self, x: T) -> Union[T, None]: "Find the largest element < x, or None if it doesn't exist." for a in reversed(self.a): if a[0] < x: return a[bisect_left(a, x) - 1] def le(self, x: T) -> Union[T, None]: "Find the largest element <= x, or None if it doesn't exist." for a in reversed(self.a): if a[0] <= x: return a[bisect_right(a, x) - 1] def gt(self, x: T) -> Union[T, None]: "Find the smallest element > x, or None if it doesn't exist." for a in self.a: if a[-1] > x: return a[bisect_right(a, x)] def ge(self, x: T) -> Union[T, None]: "Find the smallest element >= x, or None if it doesn't exist." for a in self.a: if a[-1] >= x: return a[bisect_left(a, x)] def __getitem__(self, x: int) -> T: "Return the x-th element, or IndexError if it doesn't exist." if x < 0: x += self.size if x < 0: raise IndexError for a in self.a: if x < len(a): return a[x] x -= len(a) raise IndexError def index(self, x: T) -> int: "Count the number of elements < x." ans = 0 for a in self.a: if a[-1] >= x: return ans + bisect_left(a, x) ans += len(a) return ans def index_right(self, x: T) -> int: "Count the number of elements <= x." ans = 0 for a in self.a: if a[-1] > x: return ans + bisect_right(a, x) ans += len(a) return ans n=int(input()) lr={} s=set([-1,2*10**9]) for i in range(n): x,l,r=input().split() if x not in lr: lr[x]=SortedSet() l=int(l) r=int(r) lr[x].add((int(l),int(r))) s.add(l) s.add(r) q=int(input()) query=[] for i in range(q): Q=input().split() if Q[0]=='1': query.append([1,Q[1],int(Q[2])]) if Q[0]=='2': s.add(int(Q[1])) query.append([2,int(Q[1])]) if Q[0]=='3': s.add(int(Q[2])) s.add(int(Q[3])) query.append([3,Q[1],int(Q[2]),int(Q[3])]) s=sorted(list(s)) m=len(s) d={} for i in range(m): d[s[i]]=i seg=segtree([0]*m,lambda x,y:x+y,0) for ID in lr: for l,r in lr[ID]: seg[d[l]]+=1 seg[d[r]+1]-=1 for Q in query: if Q[0]==1: x=Q[1] t=Q[2] flag=False if x in lr: m=lr[x].le((t,2*10**9)) if m and m[0]<=t<=m[1]: flag=True if flag: print('Yes') else: print('No') elif Q[0]==2: t=Q[1] print(seg.query(0,d[t]+1)) else: x,l,r=Q[1:] if x not in lr: lr[x]=SortedSet() seg[d[l]]+=1 seg[d[r]+1]-=1 lr[x].add((l,r))