結果

問題 No.2065 Sum of Min
ユーザー ニックネームニックネーム
提出日時 2022-09-02 22:47:47
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 1,336 ms / 2,000 ms
コード長 945 bytes
コンパイル時間 666 ms
コンパイル使用メモリ 87,264 KB
実行使用メモリ 168,764 KB
最終ジャッジ日時 2023-08-10 05:06:39
合計ジャッジ時間 24,101 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 68 ms
71,492 KB
testcase_01 AC 69 ms
71,180 KB
testcase_02 AC 70 ms
71,516 KB
testcase_03 AC 71 ms
71,572 KB
testcase_04 AC 616 ms
132,240 KB
testcase_05 AC 597 ms
132,504 KB
testcase_06 AC 1,028 ms
117,168 KB
testcase_07 AC 489 ms
111,324 KB
testcase_08 AC 1,044 ms
118,168 KB
testcase_09 AC 1,219 ms
167,780 KB
testcase_10 AC 1,303 ms
167,380 KB
testcase_11 AC 1,279 ms
167,556 KB
testcase_12 AC 1,291 ms
168,388 KB
testcase_13 AC 1,336 ms
167,396 KB
testcase_14 AC 1,330 ms
168,460 KB
testcase_15 AC 1,311 ms
167,536 KB
testcase_16 AC 1,319 ms
168,764 KB
testcase_17 AC 1,299 ms
168,040 KB
testcase_18 AC 1,320 ms
168,416 KB
testcase_19 AC 1,307 ms
167,840 KB
testcase_20 AC 1,302 ms
167,956 KB
testcase_21 AC 1,331 ms
168,356 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BIT:
    def __init__(self, n):
        self.n = n; self.k = [0]*(n+1)
    def a(self, i, x):
        while i <= self.n: self.k[i] += x; i += i&-i
    def s(self, i):
        t = 0
        while i > 0: t += self.k[i]; i -= i&-i
        return t
    def r(self, l, r): return self.s(r)-self.s(l-1)
n, q = map(int, input().split())
a = list(map(int, input().split()))
lrmpxi = []
vxset = set(a)
for i in range(q):
    l, r, x = map(int, input().split())
    lrmpxi.append((l-2, -1, x, i))
    lrmpxi.append((r-1, 1, x, i))
    vxset.add(x)
vxtoi = {vx: i+1 for i, vx in enumerate(sorted(vxset))}
bit_sum = BIT(n+q+1)
bit_num = BIT(n+q+1)
j = -1
ans = [0]*q
for lr, mp, x, i in sorted(lrmpxi):
    while j < lr:
        j += 1
        v = a[j]
        bit_sum.a(vxtoi[v], v)
        bit_sum.a(n+q+1, -v)
        bit_num.a(1, 1)
        bit_num.a(vxtoi[v], -1)
    ans[i] += mp*(bit_sum.s(vxtoi[x])+x*bit_num.s(vxtoi[x]))
print(*ans, sep="\n")
0