結果

問題 No.2065 Sum of Min
ユーザー ニックネームニックネーム
提出日時 2022-09-02 22:47:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,138 ms / 2,000 ms
コード長 945 bytes
コンパイル時間 161 ms
コンパイル使用メモリ 82,096 KB
実行使用メモリ 167,936 KB
最終ジャッジ日時 2024-04-27 22:26:31
合計ジャッジ時間 20,284 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 33 ms
52,980 KB
testcase_01 AC 34 ms
53,584 KB
testcase_02 AC 36 ms
52,628 KB
testcase_03 AC 37 ms
53,112 KB
testcase_04 AC 524 ms
131,544 KB
testcase_05 AC 507 ms
131,296 KB
testcase_06 AC 841 ms
116,076 KB
testcase_07 AC 418 ms
110,032 KB
testcase_08 AC 906 ms
117,064 KB
testcase_09 AC 1,061 ms
166,968 KB
testcase_10 AC 1,112 ms
166,568 KB
testcase_11 AC 1,120 ms
166,232 KB
testcase_12 AC 1,108 ms
167,168 KB
testcase_13 AC 1,135 ms
166,360 KB
testcase_14 AC 1,106 ms
167,604 KB
testcase_15 AC 1,087 ms
166,504 KB
testcase_16 AC 1,095 ms
167,936 KB
testcase_17 AC 1,123 ms
167,252 KB
testcase_18 AC 1,109 ms
167,300 KB
testcase_19 AC 1,138 ms
166,360 KB
testcase_20 AC 1,110 ms
166,688 KB
testcase_21 AC 1,102 ms
167,560 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