結果

問題 No.1012 荷物収集
ユーザー 👑 rin204rin204
提出日時 2022-07-10 17:55:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 551 ms / 2,000 ms
コード長 1,364 bytes
コンパイル時間 457 ms
コンパイル使用メモリ 87,252 KB
実行使用メモリ 175,116 KB
最終ジャッジ日時 2023-09-02 01:06:17
合計ジャッジ時間 20,609 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
71,148 KB
testcase_01 AC 68 ms
71,396 KB
testcase_02 AC 68 ms
71,156 KB
testcase_03 AC 69 ms
71,352 KB
testcase_04 AC 416 ms
174,960 KB
testcase_05 AC 411 ms
175,116 KB
testcase_06 AC 413 ms
174,772 KB
testcase_07 AC 416 ms
174,976 KB
testcase_08 AC 409 ms
174,768 KB
testcase_09 AC 412 ms
174,840 KB
testcase_10 AC 414 ms
174,960 KB
testcase_11 AC 414 ms
175,076 KB
testcase_12 AC 423 ms
175,000 KB
testcase_13 AC 421 ms
174,880 KB
testcase_14 AC 81 ms
75,716 KB
testcase_15 AC 89 ms
76,800 KB
testcase_16 AC 83 ms
75,932 KB
testcase_17 AC 89 ms
76,656 KB
testcase_18 AC 84 ms
76,796 KB
testcase_19 AC 79 ms
76,132 KB
testcase_20 AC 81 ms
75,940 KB
testcase_21 AC 84 ms
76,136 KB
testcase_22 AC 81 ms
75,768 KB
testcase_23 AC 83 ms
76,288 KB
testcase_24 AC 419 ms
126,952 KB
testcase_25 AC 509 ms
154,440 KB
testcase_26 AC 330 ms
105,276 KB
testcase_27 AC 173 ms
85,304 KB
testcase_28 AC 500 ms
142,344 KB
testcase_29 AC 344 ms
121,816 KB
testcase_30 AC 496 ms
158,056 KB
testcase_31 AC 284 ms
111,652 KB
testcase_32 AC 250 ms
102,468 KB
testcase_33 AC 335 ms
121,264 KB
testcase_34 AC 344 ms
113,068 KB
testcase_35 AC 448 ms
142,956 KB
testcase_36 AC 337 ms
121,212 KB
testcase_37 AC 334 ms
120,504 KB
testcase_38 AC 437 ms
137,028 KB
testcase_39 AC 258 ms
96,012 KB
testcase_40 AC 286 ms
109,364 KB
testcase_41 AC 551 ms
166,900 KB
testcase_42 AC 326 ms
118,892 KB
testcase_43 AC 395 ms
126,192 KB
testcase_44 AC 70 ms
71,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0