結果

問題 No.1012 荷物収集
ユーザー roarisroaris
提出日時 2020-07-08 02:12:14
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 495 ms / 2,000 ms
コード長 1,051 bytes
コンパイル時間 145 ms
コンパイル使用メモリ 82,472 KB
実行使用メモリ 176,812 KB
最終ジャッジ日時 2024-04-09 23:41:43
合計ジャッジ時間 15,205 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
55,296 KB
testcase_01 AC 42 ms
55,064 KB
testcase_02 AC 39 ms
55,108 KB
testcase_03 AC 41 ms
54,380 KB
testcase_04 AC 356 ms
176,412 KB
testcase_05 AC 350 ms
176,248 KB
testcase_06 AC 349 ms
176,692 KB
testcase_07 AC 352 ms
176,504 KB
testcase_08 AC 355 ms
176,444 KB
testcase_09 AC 353 ms
176,344 KB
testcase_10 AC 350 ms
176,812 KB
testcase_11 AC 353 ms
176,236 KB
testcase_12 AC 354 ms
176,244 KB
testcase_13 AC 354 ms
176,408 KB
testcase_14 AC 48 ms
63,564 KB
testcase_15 AC 56 ms
70,148 KB
testcase_16 AC 52 ms
65,388 KB
testcase_17 AC 56 ms
69,684 KB
testcase_18 AC 52 ms
66,588 KB
testcase_19 AC 47 ms
62,416 KB
testcase_20 AC 50 ms
63,088 KB
testcase_21 AC 53 ms
65,292 KB
testcase_22 AC 51 ms
65,740 KB
testcase_23 AC 50 ms
64,568 KB
testcase_24 AC 368 ms
138,680 KB
testcase_25 AC 443 ms
155,220 KB
testcase_26 AC 260 ms
101,500 KB
testcase_27 AC 117 ms
84,496 KB
testcase_28 AC 426 ms
123,676 KB
testcase_29 AC 273 ms
106,640 KB
testcase_30 AC 444 ms
159,340 KB
testcase_31 AC 229 ms
97,720 KB
testcase_32 AC 194 ms
102,156 KB
testcase_33 AC 277 ms
119,248 KB
testcase_34 AC 294 ms
123,896 KB
testcase_35 AC 377 ms
143,536 KB
testcase_36 AC 283 ms
121,000 KB
testcase_37 AC 264 ms
121,648 KB
testcase_38 AC 376 ms
137,564 KB
testcase_39 AC 210 ms
103,848 KB
testcase_40 AC 235 ms
110,568 KB
testcase_41 AC 495 ms
170,040 KB
testcase_42 AC 270 ms
117,672 KB
testcase_43 AC 330 ms
117,704 KB
testcase_44 AC 39 ms
54,392 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
from collections import *

def compress(l):
    l = list(set(l))
    l.sort()
    idx = defaultdict(int)

    for i in range(len(l)):
        idx[l[i]] = i
    
    return idx

class BIT:
    def __init__(self, n):
        self.n = n
        self.bit = [0]*(n+1)
    
    def add(self, i, x):
        i += 1
        
        while i<=self.n:
            self.bit[i] += x
            i += i&(-i)

    def acc(self, i):
        s = 0
        
        while i>0:
            s += self.bit[i]
            i -= i&(-i)
        
        return s

N, Q = map(int, input().split())
xw = [tuple(map(int, input().split())) for _ in range(N)]
X = list(map(int, input().split()))
l = [xwi[0] for xwi in xw]+X
idx = compress(l)
n = len(list(idx.keys()))
bit1 = BIT(n)
bit2 = BIT(n)

for x, w in xw:
    bit1.add(idx[x], w)
    bit2.add(idx[x], x*w)

for Xi in X:
    lw = bit1.acc(idx[Xi])
    lxw = bit2.acc(idx[Xi])
    rw = bit1.acc(n)-bit1.acc(idx[Xi])
    rxw = bit2.acc(n)-bit2.acc(idx[Xi])
    print(Xi*lw-lxw+rxw-Xi*rw)
0