結果

問題 No.877 Range ReLU Query
ユーザー brthyyjpbrthyyjp
提出日時 2021-03-04 06:44:41
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 986 ms / 2,000 ms
コード長 1,749 bytes
コンパイル時間 352 ms
コンパイル使用メモリ 86,996 KB
実行使用メモリ 124,628 KB
最終ジャッジ日時 2023-08-08 04:49:55
合計ジャッジ時間 11,960 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 75 ms
70,984 KB
testcase_01 AC 91 ms
76,176 KB
testcase_02 AC 90 ms
75,556 KB
testcase_03 AC 102 ms
76,692 KB
testcase_04 AC 82 ms
75,668 KB
testcase_05 AC 85 ms
75,564 KB
testcase_06 AC 83 ms
75,660 KB
testcase_07 AC 83 ms
75,740 KB
testcase_08 AC 96 ms
76,644 KB
testcase_09 AC 82 ms
75,308 KB
testcase_10 AC 87 ms
75,652 KB
testcase_11 AC 881 ms
120,440 KB
testcase_12 AC 788 ms
117,108 KB
testcase_13 AC 673 ms
110,388 KB
testcase_14 AC 665 ms
110,880 KB
testcase_15 AC 971 ms
124,372 KB
testcase_16 AC 917 ms
121,592 KB
testcase_17 AC 962 ms
122,656 KB
testcase_18 AC 943 ms
122,752 KB
testcase_19 AC 901 ms
124,628 KB
testcase_20 AC 986 ms
124,436 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class BIT:
    def __init__(self, n):
        self.n = n
        self.bit = [0]*(self.n+1) # 1-indexed

    def init(self, init_val):
        for i, v in enumerate(init_val):
            self.add(i, v)

    def add(self, i, x):
        # i: 0-indexed
        i += 1 # to 1-indexed
        while i <= self.n:
            self.bit[i] += x
            i += (i & -i)

    def sum(self, i, j):
        # return sum of [i, j)
        # i, j: 0-indexed
        return self._sum(j) - self._sum(i)

    def _sum(self, i):
        # return sum of [0, i)
        # i: 0-indexed
        res = 0
        while i > 0:
            res += self.bit[i]
            i -= i & (-i)
        return res

    def lower_bound(self, x):
        s = 0
        pos = 0
        depth = self.n.bit_length()
        v = 1 << depth
        for i in range(depth, -1, -1):
            k = pos + v
            if k <= self.n and s + self.bit[k] < x:
                    s += self.bit[k]
                    pos += v
            v >>= 1
        return pos

    def __str__(self): # for debug
        arr = [self.sum(i,i+1) for i in range(self.n)]
        return str(arr)

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

n, q = map(int, input().split())
A = list(map(int, input().split()))
Q = []
LR = []
for i, a in enumerate(A):
    Q.append((a, 1, i))
for i in range(q):
    t, l, r, x = map(int, input().split())
    l, r = l-1, r-1
    Q.append((x, 0, i))
    LR.append((l, r))

Q.sort(key=lambda x:(-x[0], x[1]))
bit1 = BIT(n+1)
bit2 = BIT(n+1)
ans = [0]*q
for a, t, i in Q:
    if t == 1:
        bit1.add(i, a)
        bit2.add(i, 1)
    else:
        l, r = LR[i]
        ans[i] = bit1.sum(l, r+1)-a*bit2.sum(l, r+1)
print(*ans, sep='\n')
0