結果

問題 No.1982 [Cherry 4th Tune B] 絶険
ユーザー ygd.ygd.
提出日時 2022-06-18 21:30:43
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 3,106 bytes
コンパイル時間 428 ms
コンパイル使用メモリ 82,392 KB
実行使用メモリ 153,140 KB
最終ジャッジ日時 2024-04-18 20:24:42
合計ジャッジ時間 18,256 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
52,608 KB
testcase_01 AC 40 ms
52,636 KB
testcase_02 AC 62 ms
79,616 KB
testcase_03 AC 479 ms
113,664 KB
testcase_04 AC 541 ms
107,132 KB
testcase_05 RE -
testcase_06 AC 686 ms
123,144 KB
testcase_07 RE -
testcase_08 AC 545 ms
111,232 KB
testcase_09 AC 656 ms
126,288 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 AC 844 ms
131,780 KB
testcase_19 RE -
testcase_20 AC 288 ms
101,760 KB
testcase_21 AC 401 ms
113,116 KB
testcase_22 RE -
testcase_23 AC 353 ms
100,620 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 AC 427 ms
118,452 KB
testcase_29 AC 795 ms
150,340 KB
testcase_30 AC 595 ms
144,364 KB
testcase_31 AC 515 ms
120,720 KB
testcase_32 AC 1,106 ms
149,296 KB
testcase_33 AC 1,023 ms
153,140 KB
testcase_34 AC 936 ms
152,712 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]*(N+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