結果
| 問題 |
No.1982 [Cherry 4th Tune B] 絶険
|
| コンテスト | |
| ユーザー |
tktk_snsn
|
| 提出日時 | 2022-06-17 23:13:35 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 2,092 ms / 3,000 ms |
| コード長 | 1,971 bytes |
| コンパイル時間 | 263 ms |
| コンパイル使用メモリ | 82,048 KB |
| 実行使用メモリ | 138,448 KB |
| 最終ジャッジ日時 | 2024-10-09 09:39:24 |
| 合計ジャッジ時間 | 38,921 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 35 |
ソースコード
import sys
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)
class FenwickTree(object):
def __init__(self, n):
self.n = n
self.log = n.bit_length()
self.data = [0] * n
def __sum(self, r):
s = 0
while r > 0:
s += self.data[r - 1]
r -= r & -r
return s
def add(self, p, x):
""" a[p] += xを行う"""
p += 1
while p <= self.n:
self.data[p - 1] += x
p += p & -p
def sum(self, l, r):
"""a[l] + a[l+1] + .. + a[r-1]を返す"""
return self.__sum(r) - self.__sum(l)
def lower_bound(self, x):
"""a[0] + a[1] + .. a[i] >= x となる最小のiを返す"""
if x <= 0:
return -1
i = 0
k = 1 << self.log
while k:
if i + k <= self.n and self.data[i + k - 1] < x:
x -= self.data[i + k - 1]
i += k
k >>= 1
return i
def __repr__(self):
res = [self.sum(i, i+1) for i in range(self.n)]
return " ".join(map(str, res))
N, K, Q = map(int, input().split())
C = [0] * K
H = [0] * K
add = []
sub = []
query = []
for i in range(K):
l, r, C[i], H[i] = map(int, input().split())
add.append((l-1, i))
sub.append((r-1, i))
for i in range(Q):
idx, x = map(int, input().split())
query.append((idx-1, x, i))
add.sort(reverse=True)
sub.sort(reverse=True)
query.sort(reverse=True)
bit = FenwickTree(K)
ans = [-1] * Q
for i in range(N):
while add and add[-1][0] == i:
_, j = add.pop()
bit.add(j, H[j])
while query and query[-1][0] == i:
_, x, idx = query.pop()
j = bit.lower_bound(x)
if j < K:
ans[idx] = C[j]
# print(i, ":", bit)
# for i in range(10):
# print(i, bit.lower_bound(i))
while sub and sub[-1][0] == i:
_, j = sub.pop()
bit.add(j, -H[j])
print(*ans, sep="\n")
tktk_snsn