結果

問題 No.2421 entersys?
ユーザー gr1msl3ygr1msl3y
提出日時 2023-08-17 18:31:09
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 2,301 bytes
コンパイル時間 372 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 220,720 KB
最終ジャッジ日時 2024-05-05 01:14:03
合計ジャッジ時間 20,598 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,864 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 AC 832 ms
187,596 KB
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

from bisect import bisect_left


class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        i += 1
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def sumrange(self, i, j):
        si = self.sum(i - 1)
        sj = self.sum(j)
        return sj - si

    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def lower_bound(self, w):  # BIT上の二分探索
        if w <= 0:
            return 0
        x = 0
        r = 1 << (self.size).bit_length()
        while r > 0:
            if x+r < self.size and self.tree[x+r] < w:
                w -= self.tree[x+r]
                x += r
            r = r >> 1
        return x


N = int(input())
data = {}
S = {-1, 2*10**9}
T = {}
for _ in range(N):
    s, l, r = input().split()
    l = int(l)
    r = int(r)+1
    if s in data:
        data[s].append([l, r])
        T[s].add(l)
        T[s].add(r)
    else:
        data[s] = [[l, r]]
        T[s] = {l, r}
    S.add(l)
    S.add(r)
Q = int(input())
qq = [list(input().split()) for _ in range(Q)]
query = []
for q in qq:
    if q[0] == '1':
        t = int(q[2])
        query.append([1, q[1], t])
        S.add(t)
    elif q[0] == '2':
        t = int(q[1])
        query.append([2, t])
        S.add(t)
    else:
        x, l, r = q[1], int(q[2]), int(q[3])
        query.append([3, x, l, r])
        S.add(l)
        S.add(r)
        if x in T:
            T[x].add(l)
            T[x].add(r)
        else:
            T[x] = {l, r}

S = sorted(list(S))
state = Bit(len(S)+1)
for k in data:
    data[k].sort()
    for l, r in data[k]:
        state.add(bisect_left(S, l), 1)
        state.add(bisect_left(S, r), -1)
    T[k] = sorted(list(T[k]))

ans = []
for q in query:
    if q[0] == 1:
        x, t = q[1], q[2]+1
        if x not in T:
            ans.append('No')
        ans.append('Yes' if bisect_left(T[x], t) else 'No')
    elif q[0] == 2:
        t = q[1]
        ans.append(state.sum(bisect_left(S, t)))
    else:
        l, r = q[2:]
        indl = bisect_left(S, l)
        indr = bisect_left(S, r)
        state.add(indl, 1)
        state.add(indr, -1)

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