結果

問題 No.2220 Range Insert & Point Mex
ユーザー ああいい
提出日時 2023-02-18 18:36:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 973 ms / 2,000 ms
コード長 1,902 bytes
コンパイル時間 248 ms
コンパイル使用メモリ 82,188 KB
実行使用メモリ 108,592 KB
最終ジャッジ日時 2024-07-21 13:01:25
合計ジャッジ時間 20,406 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 36
権限があれば一括ダウンロードができます

ソースコード

diff #

#BIT plus ver
class BITplus:
    def __init__(self,N):
        self.N = N
        self.bit = [0] * (self.N+1)
    def add(self,i,x):
        while i <= self.N:
            self.bit[i] += x
            i += i & -i
    def fold(self,i):
        ans = 0
        while i > 0:
            ans += self.bit[i]
            i -= i & -i
        return ans
    def lb(self,w):
        if w <= 0:return 0
        x = 0
        k = 1
        while k <= self.N:
            k <<= 1
        k >>= 1
        while k:
            if x + k <= self.N and self.bit[x+k] < w:
                w -= self.bit[x+k]
                x += k
            k >>= 1
        return x + 1

    #サイズ N の配列をいれる
    """
    def build(self,seq):
        bit = self.bit
        N = self.N
        for i in range(N):
            bit[i+1] = seq[i]
        for i in range(1,N+1):
            if i + (i & -1) <= N:
                bit[i + (i & -i)] += bit[i]
    """

N = int(input())
query = []
for _ in range(N):
    l,r,a = map(int,input().split())
    query.append((l,a))
    query.append((r + 1,~a))
query.sort(reverse = True)
Q = int(input())
X = list(map(int,input().split()))

C = 10 ** 5
bit = BITplus(C + 1)
from collections import defaultdict
d = defaultdict(int)

def calc():
    if 0 not in d or d[0] == 0:
        return 0
    end = C + 1
    start = 0
    while end - start > 1:
        mid = end + start >> 1
        u = bit.fold(mid + 1)
        if u <= mid:
            end = mid
        else:
            start = mid
    return start + 1
for x in X:
    while query and query[-1][0] <= x:
        k,a = query.pop()
        if a < 0:
            a = ~a
            if a > C:continue
            d[a] -= 1
            if d[a] == 0:
                bit.add(a + 1,-1)
        else:
            if a > C:continue
            d[a] += 1
            if d[a] == 1:
                bit.add(a + 1,1)
    print(calc())
0