結果

問題 No.877 Range ReLU Query
ユーザー 👑 rin204rin204
提出日時 2022-07-06 07:25:15
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,627 bytes
コンパイル時間 289 ms
コンパイル使用メモリ 87,344 KB
実行使用メモリ 152,076 KB
最終ジャッジ日時 2023-08-22 22:53:07
合計ジャッジ時間 10,712 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,244 KB
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 AC 78 ms
75,500 KB
testcase_05 RE -
testcase_06 AC 88 ms
75,492 KB
testcase_07 AC 84 ms
75,428 KB
testcase_08 AC 102 ms
76,840 KB
testcase_09 AC 79 ms
75,796 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 AC 785 ms
152,076 KB
testcase_16 AC 742 ms
149,256 KB
testcase_17 AC 755 ms
150,520 KB
testcase_18 AC 753 ms
150,696 KB
testcase_19 AC 616 ms
145,008 KB
testcase_20 AC 665 ms
149,808 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()))
se = set(A)
L = [[] for _ in range(n)]
R = [[] for _ in range(n)]
X = [0] * n
for i in range(Q):
    _, l, r, X[i] = map(int, input().split())
    L[l - 1].append(i)
    R[r - 1].append(i)
    se.add(X[i])

lst = sorted(se)
dic = {l:i for i, l in enumerate(lst)}
le = len(lst)
tot = Bit(le)
cnt = Bit(le)
ans = [0] * Q
for i, a in enumerate(A):
    for j in L[i]:
        x = dic[X[j]]
        tmp = tot.range_sum(x + 1, le) - cnt.range_sum(x + 1, le) * X[j]
        ans[j] -= tmp
    
    cnt.add(dic[a], 1)
    tot.add(dic[a], a)
    for j in R[i]:
        x = dic[X[j]]
        tmp = tot.range_sum(x + 1, le) - cnt.range_sum(x + 1, le) * X[j]
        ans[j] += tmp
    
print(*ans, sep="\n")
0