結果

問題 No.2065 Sum of Min
ユーザー ニックネームニックネーム
提出日時 2022-09-02 22:47:32
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 945 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 12,928 KB
実行使用メモリ 84,392 KB
最終ジャッジ日時 2024-04-27 22:25:33
合計ジャッジ時間 15,350 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
11,008 KB
testcase_01 AC 27 ms
10,880 KB
testcase_02 AC 25 ms
10,752 KB
testcase_03 AC 26 ms
10,880 KB
testcase_04 TLE -
testcase_05 TLE -
testcase_06 AC 1,739 ms
47,652 KB
testcase_07 AC 1,522 ms
52,696 KB
testcase_08 AC 1,821 ms
54,196 KB
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 TLE -
testcase_21 TLE -
権限があれば一括ダウンロードができます

ソースコード

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