結果

問題 No.877 Range ReLU Query
ユーザー 👑 rin204
提出日時 2022-07-06 07:25:15
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,627 bytes
コンパイル時間 209 ms
コンパイル使用メモリ 82,372 KB
実行使用メモリ 151,684 KB
最終ジャッジ日時 2024-12-18 01:36:41
合計ジャッジ時間 8,493 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 11 RE * 9
権限があれば一括ダウンロードができます

ソースコード

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