結果

問題 No.1982 [Cherry 4th Tune B] 絶険
ユーザー pitPpitP
提出日時 2022-06-19 08:26:55
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,252 ms / 3,000 ms
コード長 2,085 bytes
コンパイル時間 523 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 222,592 KB
最終ジャッジ日時 2024-04-19 12:36:39
合計ジャッジ時間 25,569 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,224 KB
testcase_01 AC 41 ms
52,608 KB
testcase_02 AC 54 ms
64,768 KB
testcase_03 AC 508 ms
140,032 KB
testcase_04 AC 568 ms
149,248 KB
testcase_05 AC 481 ms
133,632 KB
testcase_06 AC 680 ms
159,744 KB
testcase_07 AC 778 ms
169,856 KB
testcase_08 AC 612 ms
150,016 KB
testcase_09 AC 702 ms
160,384 KB
testcase_10 AC 689 ms
157,824 KB
testcase_11 AC 434 ms
125,824 KB
testcase_12 AC 720 ms
165,376 KB
testcase_13 AC 451 ms
135,296 KB
testcase_14 AC 502 ms
145,920 KB
testcase_15 AC 448 ms
134,144 KB
testcase_16 AC 596 ms
146,432 KB
testcase_17 AC 1,232 ms
200,192 KB
testcase_18 AC 1,030 ms
183,936 KB
testcase_19 AC 1,010 ms
197,632 KB
testcase_20 AC 242 ms
107,008 KB
testcase_21 AC 333 ms
116,352 KB
testcase_22 AC 507 ms
144,640 KB
testcase_23 AC 313 ms
112,512 KB
testcase_24 AC 411 ms
128,256 KB
testcase_25 AC 961 ms
194,560 KB
testcase_26 AC 956 ms
190,464 KB
testcase_27 AC 247 ms
102,016 KB
testcase_28 AC 452 ms
144,128 KB
testcase_29 AC 928 ms
222,352 KB
testcase_30 AC 658 ms
207,816 KB
testcase_31 AC 473 ms
145,792 KB
testcase_32 AC 1,252 ms
222,592 KB
testcase_33 AC 1,108 ms
221,056 KB
testcase_34 AC 1,082 ms
220,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

#先頭からのsum,addをO(logN)
class Fenwick_Tree:
    def __init__(self, n):
        self._n = n  # 要素数
        self.data = [0] * n
        self.depth = n.bit_length()

    def add(self, p, x):
        assert 0 <= p < self._n
        p += 1  # 0-indexed -> 1-indexed
        while p <= self._n:
            self.data[p - 1] += x # dataを更新
            p += p & -p  # pにLSB(p)を加算,data[i]の長さを示す
    
    def _sum(self, r):#s = a0+a1+...+a[r-1] or 0
        s = 0  # 総和を入れる変数
        while r > 0:
            s += self.data[r - 1]
            r -= r & -r  # rからLSB(r)を減算
        return s
    
    def sum(self, l, r):#[l,r)の総和
        assert 0 <= l <= r <= self._n
        return self._sum(r) - self._sum(l)

    def bisect_l(self,x): #wa >= xとなる最小のidx
        pos = 0 ; wa = 0
        for i in range(self.depth,-1,-1):
            k = pos + (1<<i)
            if k < self._n and wa + self.data[k-1] < x:
                wa += self.data[k-1]
                pos += (1<<i)
        return pos 
    
    def bisect_r(self,x): #wa >= xとなる最大のidx
        if x < 0 : return 0
        pos = 0 ; wa = 0
        for i in range(self.depth+1,-1,-1):
            k = pos + (1 << i)
            if k <= self._n and wa + self.data[k-1] <= x:
                wa += self.data[k-1]
                pos += (1<<i)
        return pos

n,k,q = map(int,input().split())
lrch = [list(map(int,input().split())) for _ in range(k)]
ix = [list(map(int,input().split())) for _ in range(q)]

Q = [[] for _ in range(n+2)]
for idx , (l,_,_,h) in enumerate(lrch):
    Q[l].append([True,h,idx])
for ans_idx , (i,x) in enumerate(ix):
    Q[i].append([False,ans_idx,x])
for idx , (_,r,_,h) in enumerate(lrch):
    Q[r].append([True,-h,idx])


ans = [-1] * q
fw = Fenwick_Tree(k+2)
for i in range(n+2):
    for boo,x,y in Q[i]:
        if boo : fw.add(y,x)
        else :
            idx = fw.bisect_l(y)
            if idx >= k : continue
            ans[x] = lrch[idx][2]

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