結果

問題 No.2065 Sum of Min
ユーザー 👑 rin204rin204
提出日時 2022-09-02 21:31:01
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 882 ms / 2,000 ms
コード長 1,425 bytes
コンパイル時間 1,201 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 106,620 KB
最終ジャッジ日時 2023-08-10 03:25:04
合計ジャッジ時間 19,060 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
71,424 KB
testcase_01 AC 76 ms
71,396 KB
testcase_02 AC 77 ms
71,452 KB
testcase_03 AC 77 ms
71,448 KB
testcase_04 AC 558 ms
104,508 KB
testcase_05 AC 557 ms
103,312 KB
testcase_06 AC 711 ms
104,980 KB
testcase_07 AC 283 ms
100,440 KB
testcase_08 AC 699 ms
106,620 KB
testcase_09 AC 862 ms
105,504 KB
testcase_10 AC 815 ms
103,808 KB
testcase_11 AC 811 ms
105,528 KB
testcase_12 AC 848 ms
104,780 KB
testcase_13 AC 863 ms
105,372 KB
testcase_14 AC 846 ms
104,864 KB
testcase_15 AC 855 ms
105,120 KB
testcase_16 AC 870 ms
105,640 KB
testcase_17 AC 876 ms
106,300 KB
testcase_18 AC 861 ms
105,636 KB
testcase_19 AC 859 ms
105,528 KB
testcase_20 AC 870 ms
106,032 KB
testcase_21 AC 882 ms
105,252 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())
A = list(map(int, input().split()))
B = [(a, i) for i, a in enumerate(A)]
B.sort()
query = []
for i in range(Q):
    l, r, x = map(int, input().split())
    l -= 1
    query.append((x, l, r, i))
query.sort()
ans = 0

cnt = Bit(n)
tot = Bit(n)
B.append((1 << 50, -1))
t = 0
ans = [0] * Q
for x, l, r, i in query:
    while B[t][0] < x:
        tot.add(B[t][1], B[t][0])
        cnt.add(B[t][1], 1)
        t += 1

    cn = cnt.range_sum(l, r)
    to = tot.range_sum(l, r)
    ans[i] = to + (r - l - cn) * x

print(*ans, sep="\n")
0