結果

問題 No.1982 [Cherry 4th Tune B] 絶険
ユーザー tktk_snsntktk_snsn
提出日時 2022-06-17 23:13:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 2,226 ms / 3,000 ms
コード長 1,971 bytes
コンパイル時間 207 ms
コンパイル使用メモリ 81,972 KB
実行使用メモリ 138,440 KB
最終ジャッジ日時 2024-04-17 15:37:52
合計ジャッジ時間 41,301 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,224 KB
testcase_01 AC 42 ms
52,480 KB
testcase_02 AC 55 ms
60,672 KB
testcase_03 AC 908 ms
108,100 KB
testcase_04 AC 1,143 ms
115,712 KB
testcase_05 AC 932 ms
95,684 KB
testcase_06 AC 1,208 ms
109,056 KB
testcase_07 AC 1,439 ms
111,472 KB
testcase_08 AC 1,090 ms
114,304 KB
testcase_09 AC 1,159 ms
110,464 KB
testcase_10 AC 1,237 ms
109,440 KB
testcase_11 AC 798 ms
94,976 KB
testcase_12 AC 1,339 ms
116,836 KB
testcase_13 AC 946 ms
108,288 KB
testcase_14 AC 1,195 ms
102,912 KB
testcase_15 AC 891 ms
106,284 KB
testcase_16 AC 1,052 ms
98,176 KB
testcase_17 AC 1,920 ms
129,152 KB
testcase_18 AC 1,620 ms
121,312 KB
testcase_19 AC 1,871 ms
127,244 KB
testcase_20 AC 379 ms
90,112 KB
testcase_21 AC 502 ms
87,500 KB
testcase_22 AC 1,074 ms
111,964 KB
testcase_23 AC 476 ms
91,980 KB
testcase_24 AC 824 ms
96,640 KB
testcase_25 AC 1,879 ms
127,872 KB
testcase_26 AC 1,744 ms
125,440 KB
testcase_27 AC 492 ms
86,016 KB
testcase_28 AC 1,057 ms
109,868 KB
testcase_29 AC 1,319 ms
138,048 KB
testcase_30 AC 497 ms
131,528 KB
testcase_31 AC 920 ms
112,000 KB
testcase_32 AC 2,226 ms
138,440 KB
testcase_33 AC 1,563 ms
137,472 KB
testcase_34 AC 1,591 ms
138,312 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)


class FenwickTree(object):
    def __init__(self, n):
        self.n = n
        self.log = n.bit_length()
        self.data = [0] * n

    def __sum(self, r):
        s = 0
        while r > 0:
            s += self.data[r - 1]
            r -= r & -r
        return s

    def add(self, p, x):
        """ a[p] += xを行う"""
        p += 1
        while p <= self.n:
            self.data[p - 1] += x
            p += p & -p

    def sum(self, l, r):
        """a[l] + a[l+1] + .. + a[r-1]を返す"""
        return self.__sum(r) - self.__sum(l)

    def lower_bound(self, x):
        """a[0] + a[1] + .. a[i] >= x となる最小のiを返す"""
        if x <= 0:
            return -1
        i = 0
        k = 1 << self.log
        while k:
            if i + k <= self.n and self.data[i + k - 1] < x:
                x -= self.data[i + k - 1]
                i += k
            k >>= 1
        return i

    def __repr__(self):
        res = [self.sum(i, i+1) for i in range(self.n)]
        return " ".join(map(str, res))


N, K, Q = map(int, input().split())
C = [0] * K
H = [0] * K
add = []
sub = []
query = []
for i in range(K):
    l, r, C[i], H[i] = map(int, input().split())
    add.append((l-1, i))
    sub.append((r-1, i))
for i in range(Q):
    idx, x = map(int, input().split())
    query.append((idx-1, x, i))

add.sort(reverse=True)
sub.sort(reverse=True)
query.sort(reverse=True)

bit = FenwickTree(K)
ans = [-1] * Q
for i in range(N):
    while add and add[-1][0] == i:
        _, j = add.pop()
        bit.add(j, H[j])
    while query and query[-1][0] == i:
        _, x, idx = query.pop()
        j = bit.lower_bound(x)
        if j < K:
            ans[idx] = C[j]
    # print(i, ":", bit)
    # for i in range(10):
    #     print(i, bit.lower_bound(i))
    while sub and sub[-1][0] == i:
        _, j = sub.pop()
        bit.add(j, -H[j])

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