結果

問題 No.1982 [Cherry 4th Tune B] 絶険
ユーザー aaaaaaaaaa2230aaaaaaaaaa2230
提出日時 2022-06-17 22:15:03
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 1,180 ms / 3,000 ms
コード長 1,661 bytes
コンパイル時間 314 ms
コンパイル使用メモリ 86,884 KB
実行使用メモリ 204,948 KB
最終ジャッジ日時 2023-07-30 13:04:58
合計ジャッジ時間 27,972 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,076 KB
testcase_01 AC 70 ms
71,172 KB
testcase_02 AC 78 ms
77,248 KB
testcase_03 AC 525 ms
129,572 KB
testcase_04 AC 592 ms
137,256 KB
testcase_05 AC 506 ms
126,792 KB
testcase_06 AC 676 ms
147,476 KB
testcase_07 AC 783 ms
158,404 KB
testcase_08 AC 619 ms
139,564 KB
testcase_09 AC 735 ms
149,312 KB
testcase_10 AC 735 ms
147,364 KB
testcase_11 AC 483 ms
119,884 KB
testcase_12 AC 784 ms
151,464 KB
testcase_13 AC 472 ms
125,644 KB
testcase_14 AC 516 ms
135,868 KB
testcase_15 AC 469 ms
124,864 KB
testcase_16 AC 613 ms
140,112 KB
testcase_17 AC 999 ms
181,264 KB
testcase_18 AC 961 ms
169,152 KB
testcase_19 AC 944 ms
180,344 KB
testcase_20 AC 300 ms
103,956 KB
testcase_21 AC 361 ms
113,428 KB
testcase_22 AC 539 ms
133,396 KB
testcase_23 AC 363 ms
109,024 KB
testcase_24 AC 450 ms
121,388 KB
testcase_25 AC 924 ms
176,472 KB
testcase_26 AC 914 ms
173,716 KB
testcase_27 AC 271 ms
99,672 KB
testcase_28 AC 455 ms
133,988 KB
testcase_29 AC 945 ms
204,948 KB
testcase_30 AC 805 ms
200,880 KB
testcase_31 AC 564 ms
134,296 KB
testcase_32 AC 1,180 ms
200,688 KB
testcase_33 AC 1,102 ms
200,700 KB
testcase_34 AC 1,063 ms
200,788 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