結果

問題 No.2220 Range Insert & Point Mex
ユーザー とりゐとりゐ
提出日時 2023-02-17 21:45:38
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 758 ms / 2,000 ms
コード長 3,157 bytes
コンパイル時間 333 ms
コンパイル使用メモリ 87,360 KB
実行使用メモリ 143,488 KB
最終ジャッジ日時 2023-09-28 18:00:40
合計ジャッジ時間 17,603 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
78,904 KB
testcase_01 AC 87 ms
78,908 KB
testcase_02 AC 88 ms
79,008 KB
testcase_03 AC 96 ms
79,320 KB
testcase_04 AC 86 ms
79,136 KB
testcase_05 AC 90 ms
79,292 KB
testcase_06 AC 89 ms
79,064 KB
testcase_07 AC 90 ms
79,352 KB
testcase_08 AC 90 ms
79,068 KB
testcase_09 AC 92 ms
79,240 KB
testcase_10 AC 92 ms
79,316 KB
testcase_11 AC 88 ms
79,120 KB
testcase_12 AC 90 ms
79,480 KB
testcase_13 AC 751 ms
139,644 KB
testcase_14 AC 758 ms
139,624 KB
testcase_15 AC 755 ms
139,652 KB
testcase_16 AC 755 ms
139,732 KB
testcase_17 AC 752 ms
139,412 KB
testcase_18 AC 748 ms
139,656 KB
testcase_19 AC 741 ms
139,392 KB
testcase_20 AC 622 ms
133,436 KB
testcase_21 AC 613 ms
133,424 KB
testcase_22 AC 629 ms
133,668 KB
testcase_23 AC 470 ms
143,488 KB
testcase_24 AC 401 ms
117,072 KB
testcase_25 AC 350 ms
118,632 KB
testcase_26 AC 447 ms
138,708 KB
testcase_27 AC 328 ms
109,704 KB
testcase_28 AC 179 ms
98,460 KB
testcase_29 AC 185 ms
96,692 KB
testcase_30 AC 181 ms
96,932 KB
testcase_31 AC 368 ms
116,840 KB
testcase_32 AC 349 ms
112,720 KB
testcase_33 AC 330 ms
113,360 KB
testcase_34 AC 681 ms
142,060 KB
testcase_35 AC 696 ms
141,704 KB
testcase_36 AC 608 ms
140,540 KB
testcase_37 AC 619 ms
140,248 KB
testcase_38 AC 454 ms
140,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
input=lambda :stdin.readline()[:-1]


class segtree():
    n=1
    size=1
    log=2
    d=[0]
    op=None
    e=10**15
    def __init__(self,V,OP,E):
        self.n=len(V)
        self.op=OP
        self.e=E
        self.log=(self.n-1).bit_length()
        self.size=1<<self.log
        self.d=[E for i in range(2*self.size)]
        for i in range(self.n):
            self.d[self.size+i]=V[i]
        for i in range(self.size-1,0,-1):
            self.update(i)
    def set(self,p,x):
        assert 0<=p and p<self.n
        p+=self.size
        self.d[p]=x
        for i in range(1,self.log+1):
            self.update(p>>i)
    def get(self,p):
        assert 0<=p and p<self.n
        return self.d[p+self.size]
    def prod(self,l,r):
        assert 0<=l and l<=r and r<=self.n
        sml=self.e
        smr=self.e
        l+=self.size
        r+=self.size
        while(l<r):
            if (l&1):
                sml=self.op(sml,self.d[l])
                l+=1
            if (r&1):
                smr=self.op(self.d[r-1],smr)
                r-=1
            l>>=1
            r>>=1
        return self.op(sml,smr)
    def all_prod(self):
        return self.d[1]
    def max_right(self,l,f):
        assert 0<=l and l<=self.n
        assert f(self.e)
        if l==self.n:
            return self.n
        l+=self.size
        sm=self.e
        while(1):
            while(l%2==0):
                l>>=1
            if not(f(self.op(sm,self.d[l]))):
                while(l<self.size):
                    l=2*l
                    if f(self.op(sm,self.d[l])):
                        sm=self.op(sm,self.d[l])
                        l+=1
                return l-self.size
            sm=self.op(sm,self.d[l])
            l+=1
            if (l&-l)==l:
                break
        return self.n
    def min_left(self,r,f):
        assert 0<=r and r<self.n
        assert f(self.e)
        if r==0:
            return 0
        r+=self.size
        sm=self.e
        while(1):
            r-=1
            while(r>1 & (r%2)):
                r>>=1
            if not(f(self.op(self.d[r],sm))):
                while(r<self.size):
                    r=(2*r+1)
                    if f(self.op(self.d[r],sm)):
                        sm=self.op(self.d[r],sm)
                        r-=1
                return r+1-self.size
            sm=self.op(self.d[r],sm)
            if (r& -r)==r:
                break
        return 0
    def update(self,k):
        self.d[k]=self.op(self.d[2*k],self.d[2*k+1])
    def __str__(self):
        return str([self.get(i) for i in range(self.n)])

n=int(input())
query=[]
for _ in range(n):  
  l,r,a=map(int,input().split())
  query.append((l,a,0))
  query.append((r+1,a,1))

q=int(input())
x=list(map(int,input().split()))
for i in range(q):
  query.append((x[i],i,2))
  
query.sort(key=lambda x:3*x[0]+x[2])

ans=[0]*q
m=10**5+10
seg=segtree([0]*m,min,10**9)
for x,y,z in query:
  if z==0:
    if y<m:
      seg.set(y,seg.get(y)+1)
  if z==1:
    if y<m:
      seg.set(y,seg.get(y)-1)
  if z==2:
    def f(x):
      return x>=1
    ans[y]=seg.max_right(0,f)

print(*ans,sep='\n')
0