結果

問題 No.1982 [Cherry 4th Tune B] 絶険
ユーザー ygd.ygd.
提出日時 2022-06-18 21:30:01
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 3,106 bytes
コンパイル時間 303 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 153,972 KB
最終ジャッジ日時 2024-04-18 20:23:32
合計ジャッジ時間 40,979 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
153,972 KB
testcase_01 AC 29 ms
11,008 KB
testcase_02 AC 310 ms
54,912 KB
testcase_03 AC 1,386 ms
78,976 KB
testcase_04 AC 1,662 ms
69,260 KB
testcase_05 RE -
testcase_06 AC 2,441 ms
99,504 KB
testcase_07 RE -
testcase_08 AC 1,784 ms
76,868 KB
testcase_09 AC 2,208 ms
103,092 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 TLE -
testcase_19 RE -
testcase_20 AC 676 ms
56,192 KB
testcase_21 AC 1,147 ms
76,244 KB
testcase_22 RE -
testcase_23 AC 875 ms
54,864 KB
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 AC 1,202 ms
90,368 KB
testcase_29 TLE -
testcase_30 TLE -
testcase_31 AC 1,282 ms
90,368 KB
testcase_32 TLE -
testcase_33 -- -
testcase_34 -- -
権限があれば一括ダウンロードができます

ソースコード

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