結果

問題 No.877 Range ReLU Query
ユーザー neterukunneterukun
提出日時 2020-09-28 04:00:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 546 ms / 2,000 ms
コード長 1,397 bytes
コンパイル時間 346 ms
コンパイル使用メモリ 82,344 KB
実行使用メモリ 107,096 KB
最終ジャッジ日時 2024-04-25 22:25:19
合計ジャッジ時間 7,563 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
53,456 KB
testcase_01 AC 53 ms
66,204 KB
testcase_02 AC 52 ms
64,964 KB
testcase_03 AC 58 ms
69,268 KB
testcase_04 AC 45 ms
61,660 KB
testcase_05 AC 48 ms
64,012 KB
testcase_06 AC 49 ms
63,636 KB
testcase_07 AC 48 ms
62,664 KB
testcase_08 AC 58 ms
70,088 KB
testcase_09 AC 46 ms
60,372 KB
testcase_10 AC 51 ms
64,488 KB
testcase_11 AC 500 ms
102,092 KB
testcase_12 AC 456 ms
100,604 KB
testcase_13 AC 368 ms
95,024 KB
testcase_14 AC 397 ms
95,244 KB
testcase_15 AC 527 ms
102,896 KB
testcase_16 AC 518 ms
105,668 KB
testcase_17 AC 546 ms
105,424 KB
testcase_18 AC 535 ms
107,096 KB
testcase_19 AC 506 ms
103,568 KB
testcase_20 AC 538 ms
103,188 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from operator import itemgetter
import sys
input = sys.stdin.buffer.readline


class BinaryIndexedTree:
    def __init__(self, n):
        self.size = n
        self.bit = [0] * (n + 1)

    def build(self, array):
        for i, val in enumerate(array):
            self.bit[i + 1] = val
        for i in range(1, self.size):
            if i + (i & -i) > self.size:
                continue
            self.bit[i + (i & -i)] += self.bit[i]

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

    def add(self, i, val):
        i += 1
        while i <= self.size:
            self.bit[i] += val
            i += i & -i

    def sum(self, l, r):
        return self._sum(r) - self._sum(l)


n, q = map(int, input().split())
a = list(map(int, input().split()))
queries = [[i] + list(map(int, input().split())) for i in range(q)]


queries.sort(key=itemgetter(4), reverse=True)
a = [(i, val) for i, val in enumerate(a)]
a.sort(key=itemgetter(1), reverse=True)

bit_cnt = BinaryIndexedTree(n)
bit_val = BinaryIndexedTree(n)
ans = [0] * q
a_ind = 0
for i, _, l, r, x in queries:
    while a_ind < n and a[a_ind][1] >= x:
        ai, val = a[a_ind]
        bit_cnt.add(ai, 1)
        bit_val.add(ai, val)
        a_ind += 1
    l -= 1
    ans[i] = bit_val.sum(l, r) - bit_cnt.sum(l, r) * x

print("\n".join(map(str, ans)))
0