結果
| 問題 |
No.1982 [Cherry 4th Tune B] 絶険
|
| コンテスト | |
| ユーザー |
ygd.
|
| 提出日時 | 2022-06-18 21:30:43 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 3,106 bytes |
| コンパイル時間 | 226 ms |
| コンパイル使用メモリ | 82,400 KB |
| 実行使用メモリ | 153,192 KB |
| 最終ジャッジ日時 | 2024-10-10 13:49:41 |
| 合計ジャッジ時間 | 16,865 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 RE * 16 |
ソースコード
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()
ygd.