結果

問題 No.1982 [Cherry 4th Tune B] 絶険
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-06-17 22:15:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,220 ms / 3,000 ms
コード長 1,661 bytes
コンパイル時間 186 ms
コンパイル使用メモリ 82,560 KB
実行使用メモリ 204,232 KB
最終ジャッジ日時 2024-04-17 14:18:54
合計ジャッジ時間 25,528 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,224 KB
testcase_01 AC 42 ms
51,968 KB
testcase_02 AC 54 ms
64,768 KB
testcase_03 AC 556 ms
129,408 KB
testcase_04 AC 591 ms
135,604 KB
testcase_05 AC 509 ms
125,616 KB
testcase_06 AC 700 ms
147,072 KB
testcase_07 AC 804 ms
157,056 KB
testcase_08 AC 614 ms
137,728 KB
testcase_09 AC 699 ms
148,992 KB
testcase_10 AC 693 ms
145,664 KB
testcase_11 AC 415 ms
118,568 KB
testcase_12 AC 726 ms
150,016 KB
testcase_13 AC 466 ms
123,904 KB
testcase_14 AC 515 ms
135,196 KB
testcase_15 AC 466 ms
123,392 KB
testcase_16 AC 615 ms
139,136 KB
testcase_17 AC 1,032 ms
181,684 KB
testcase_18 AC 901 ms
168,320 KB
testcase_19 AC 1,007 ms
179,456 KB
testcase_20 AC 294 ms
103,040 KB
testcase_21 AC 384 ms
112,000 KB
testcase_22 AC 567 ms
132,096 KB
testcase_23 AC 358 ms
107,520 KB
testcase_24 AC 440 ms
119,660 KB
testcase_25 AC 985 ms
175,044 KB
testcase_26 AC 970 ms
173,056 KB
testcase_27 AC 262 ms
98,944 KB
testcase_28 AC 457 ms
132,864 KB
testcase_29 AC 932 ms
204,232 KB
testcase_30 AC 694 ms
199,948 KB
testcase_31 AC 490 ms
133,632 KB
testcase_32 AC 1,220 ms
200,064 KB
testcase_33 AC 1,132 ms
199,936 KB
testcase_34 AC 1,098 ms
200,192 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BIT:
    def __init__(self, n):
        self.size = n
        self.tree = [0]*(n+1)
 
    def build(self, list):
        self.tree[1:] = list.copy()
        for i in range(self.size+1):
            j = i + (i & (-i))
            if j < self.size+1:
                self.tree[j] += self.tree[i]

    def sum(self, i):
        # [0, i) の要素の総和を返す
        s = 0
        while i>0:
            s += self.tree[i]
            i -= i & -i
        return s
    # 0 index を 1 index に変更  転倒数を求めるなら1を足していく
    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    # 総和がx以上になる位置のindex をbinary search
    def bsearch(self,x):
        le = 0
        ri = 1<<(self.size.bit_length()-1)
        while ri > 0:
            if le+ri <= self.size and self.tree[le+ri]<x:
                x -= self.tree[le+ri]
                le += ri
            ri >>= 1
        return le+1

n,k,q = map(int,input().split())
Q = [list(map(int,input().split())) for i in range(k)]
IX = [list(map(int,input().split())) for i in range(q)]

query = [[] for i in range(n+5)]
ans = [-1]*q
bit = BIT(k+5)

for i,(l,r,c,h) in enumerate(Q):
    query[l].append([0,h,i])
for ind,(i,x) in enumerate(IX):
    query[i].append([1,ind,x])
for i,(l,r,c,h) in enumerate(Q):
    query[r].append([0,-h,i])

for i in range(n+5):
    for id,x,y in query[i]:
        if id == 0:
            bit.add(y,x)
        else:
            ind = bit.bsearch(y)
            if ind > k + 1:
                continue
            ans[x] = Q[ind-1][2]
for i in ans:
    print(i)
0