結果

問題 No.1982 [Cherry 4th Tune B] 絶険
ユーザー ygd.ygd.
提出日時 2022-06-18 21:33:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,188 ms / 3,000 ms
コード長 3,106 bytes
コンパイル時間 349 ms
コンパイル使用メモリ 82,272 KB
実行使用メモリ 153,124 KB
最終ジャッジ日時 2024-04-18 20:31:02
合計ジャッジ時間 23,813 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 40 ms
52,608 KB
testcase_01 AC 39 ms
52,352 KB
testcase_02 AC 66 ms
77,824 KB
testcase_03 AC 509 ms
112,768 KB
testcase_04 AC 506 ms
106,368 KB
testcase_05 AC 451 ms
103,408 KB
testcase_06 AC 679 ms
122,604 KB
testcase_07 AC 703 ms
123,596 KB
testcase_08 AC 514 ms
110,692 KB
testcase_09 AC 641 ms
125,528 KB
testcase_10 AC 595 ms
110,712 KB
testcase_11 AC 399 ms
95,940 KB
testcase_12 AC 676 ms
112,272 KB
testcase_13 AC 420 ms
95,744 KB
testcase_14 AC 451 ms
99,968 KB
testcase_15 AC 391 ms
96,400 KB
testcase_16 AC 611 ms
114,688 KB
testcase_17 AC 922 ms
135,800 KB
testcase_18 AC 872 ms
132,448 KB
testcase_19 AC 978 ms
137,340 KB
testcase_20 AC 256 ms
100,608 KB
testcase_21 AC 376 ms
111,756 KB
testcase_22 AC 449 ms
98,792 KB
testcase_23 AC 333 ms
99,864 KB
testcase_24 AC 371 ms
93,772 KB
testcase_25 AC 810 ms
120,712 KB
testcase_26 AC 844 ms
130,576 KB
testcase_27 AC 253 ms
87,440 KB
testcase_28 AC 384 ms
116,812 KB
testcase_29 AC 763 ms
150,112 KB
testcase_30 AC 561 ms
144,616 KB
testcase_31 AC 484 ms
119,040 KB
testcase_32 AC 1,188 ms
148,832 KB
testcase_33 AC 1,124 ms
153,124 KB
testcase_34 AC 971 ms
152,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = sys.stdin.readline
#input = sys.stdin.buffer.readline #文字列はダメ
#sys.setrecursionlimit(1000000)
#import bisect
#import itertools
#import random
#from heapq import heapify, heappop, heappush
#from collections import defaultdict 
#from collections import deque
#import copy
#import math
#from functools import lru_cache
#@lru_cache(maxsize=None)
MOD = pow(10,9) + 7
#MOD = 998244353
#dx = [1,0,-1,0]
#dy = [0,1,0,-1]
#dx8 = [1,1,0,-1,-1,-1,0,1]
#dy8 = [0,1,1,1,0,-1,-1,-1]

# B = BIT([0]*M)
class BIT: #1-index
    def __init__(self,init_value):
        self.n = len(init_value)
        self.tree = [0]*(self.n+1)
        for i in range(1,self.n+1):
            x = init_value[i-1]
            while i <= self.n:
                self.tree[i] += x
                i += i & (-i)
 
    def add(self,i,x): 
        while i <= self.n:
            self.tree[i] += x
            i += i & (-i)
        return
 
    def to_sum(self,i):
        res = 0
        while i > 0:
            res += self.tree[i]
            i -= i & (-i)
        return res
 
    # get(i,i)でi番目を取得
    def get(self, i, j):
        return self.to_sum(j)-self.to_sum(i-1)

    def lower_bound(self,x):  # a_1+…+a_i >= x となる最小のi
        res = 0
        r = 1
        while r <= self.n:
            r <<= 1
        while r:
            if res+r <= self.n and self.tree[res+r] < x:
                x -= self.tree[res+r]
                res += r
            r >>= 1
        return res+1

def main():
    # N: 横, K: 壁の種類, Q: クエリ
    N,K,Q = map(int,input().split())
    wall_colors = [-1]*(K+1)
    # 何番目の壁で高さいくつが追加/消去されるか。
    wall_start = [[] for _ in range(N+2)]
    wall_end = [[] for _ in range(N+2)]
    for i in range(K):
        L,R,C,H = map(int,input().split())
        wall_start[L].append((i+1,H))
        wall_end[R+1].append((i+1,H))
        wall_colors[i+1] = C
    
    #print(wall_start)
    #print(wall_end)

    # queries[i]: i番目(1-index)の壁に対するクエリ
    queries = [[] for _ in range(N+1)]
    for i in range(Q):
        I,X = map(int,input().split())
        queries[I].append((i,X))
    
    ans = [-1]*Q

    # i番目(1-index)の壁の高さが今どうなっているか。
    Tree = BIT([0]*K)


    for x in range(1,N+1):
        # i番目(1-index)の壁が、H伸びる。
        for i,H in wall_start[x]:
            #print("start",i,H)
            Tree.add(i,H)
        # i番目(1-index)の壁が、H消える。
        for i,H in wall_end[x]:
            #print("end",i,H)
            Tree.add(i,-H)
        
        # デバッグ用
        # state = []
        # for i in range(1,K+1):
        #     state.append(Tree.get(i,i))
        #print(x,state)
        
        for idx, height in queries[x]:
            #print("zenbu",Tree.to_sum(K), height)
            if Tree.to_sum(K) < height:
                continue 
            ci = Tree.lower_bound(height)
            ans[idx] = wall_colors[ci]
    
    print(*ans,sep="\n")
        




if __name__ == '__main__':
    main()
0