結果
| 問題 |
No.1012 荷物収集
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2022-07-10 17:55:44 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
AC
|
| 実行時間 | 559 ms / 2,000 ms |
| コード長 | 1,364 bytes |
| コンパイル時間 | 343 ms |
| コンパイル使用メモリ | 82,432 KB |
| 実行使用メモリ | 174,088 KB |
| 最終ジャッジ日時 | 2024-06-11 07:42:52 |
| 合計ジャッジ時間 | 16,653 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 41 |
ソースコード
class Bit:
def __init__(self, n):
self.size = n
self.n0 = 1 << (n.bit_length() - 1)
self.tree = [0] * (n + 1)
def range_sum(self, l, r):
return self.sum(r - 1) - self.sum(l - 1)
def sum(self, i):
i += 1
s = 0
while i > 0:
s += self.tree[i]
i -= i & -i
return s
def get(self, i):
return self.sum(i) - self.sum(i - 1)
def add(self, i, x):
i += 1
while i <= self.size:
self.tree[i] += x
i += i & -i
def lower_bound(self, x):
pos = 0
plus = self.n0
while plus > 0:
if pos + plus <= self.size and self.tree[pos + plus] < x:
x -= self.tree[pos + plus]
pos += plus
plus //= 2
return pos
n, Q = map(int, input().split())
xw = [list(map(int, input().split())) for _ in range(n)]
X = list(map(int, input().split()))
se = set()
for x, _ in xw:
se.add(x)
for x in X:
se.add(x)
lst = sorted(se)
dic = {l:i for i, l in enumerate(lst)}
le = len(lst)
cnt = Bit(le)
tot = Bit(le)
for x, w in xw:
cnt.add(dic[x], w)
tot.add(dic[x], x * w)
for x in X:
ans = x * cnt.sum(dic[x]) - tot.sum(dic[x])
ans += tot.range_sum(dic[x], le) - x * cnt.range_sum(dic[x], le)
print(ans)