結果
問題 | No.1982 [Cherry 4th Tune B] 絶険 |
ユーザー | ああいい |
提出日時 | 2022-07-17 18:04:58 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 959 ms / 3,000 ms |
コード長 | 1,614 bytes |
コンパイル時間 | 156 ms |
コンパイル使用メモリ | 82,628 KB |
実行使用メモリ | 150,808 KB |
最終ジャッジ日時 | 2024-06-29 19:26:21 |
合計ジャッジ時間 | 20,988 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 35 |
ソースコード
#BIT plus ver class BITplus: def __init__(self,N): self.N = N self.bit = [0] * (self.N+1) def add(self,i,x): while i <= self.N: self.bit[i] += x i += i & -i def fold(self,i): ans = 0 while i > 0: ans += self.bit[i] i -= i & -i return ans def lb(self,w): if w <= 0:return 0 x = 0 k = 1 while k <= self.N: k <<= 1 k >>= 1 while k: if x + k <= self.N and self.bit[x+k] < w: w -= self.bit[x+k] x += k k >>= 1 return x + 1 #サイズ N の配列をいれる def build(self,seq): bit = self.bit N = self.N for i in range(N): bit[i+1] = seq[i] for i in range(1,N+1): if i + (i & -1) <= N: bit[i + (i & -i)] += bit[i] import sys rr = sys.stdin N,K,Q = map(int,rr.readline().split()) sousa = [[] for _ in range(N + 2)] col = [] for _ in range(K): l,r,c,h = map(int,rr.readline().split()) sousa[l].append((_,h)) sousa[r + 1].append((_,-h)) col.append(c) bit = BITplus(K) query = [] for _ in range(Q): i,x = map(int,input().split()) query.append((i,x,_)) query.sort(key = lambda x:x[0]) ans = [0] * Q now = 0 for i,x,_ in query: while now <= i: for q,d in sousa[now]: bit.add(q + 1,d) now += 1 tmp = bit.fold(K) #print(tmp) if tmp < x: ans[_] = -1 continue t = bit.lb(x) ans[_] = col[t - 1] print(*ans,sep = "\n")