結果

問題 No.877 Range ReLU Query
ユーザー ああいいああいい
提出日時 2022-04-19 18:08:03
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 735 ms / 2,000 ms
コード長 1,853 bytes
コンパイル時間 467 ms
コンパイル使用メモリ 82,572 KB
実行使用メモリ 118,516 KB
最終ジャッジ日時 2024-04-25 22:36:29
合計ジャッジ時間 8,775 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,120 KB
testcase_01 AC 63 ms
70,096 KB
testcase_02 AC 63 ms
69,228 KB
testcase_03 AC 69 ms
71,628 KB
testcase_04 AC 47 ms
60,584 KB
testcase_05 AC 51 ms
64,000 KB
testcase_06 AC 54 ms
65,060 KB
testcase_07 AC 51 ms
63,564 KB
testcase_08 AC 68 ms
72,620 KB
testcase_09 AC 45 ms
60,432 KB
testcase_10 AC 59 ms
68,468 KB
testcase_11 AC 621 ms
112,856 KB
testcase_12 AC 567 ms
107,072 KB
testcase_13 AC 482 ms
103,624 KB
testcase_14 AC 493 ms
101,716 KB
testcase_15 AC 735 ms
118,516 KB
testcase_16 AC 691 ms
114,144 KB
testcase_17 AC 696 ms
114,372 KB
testcase_18 AC 685 ms
115,088 KB
testcase_19 AC 607 ms
115,356 KB
testcase_20 AC 657 ms
116,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #


class SegTree:
    #単位元と結合演算はここ変える
    #いろんな種類のsegは作れないかも
    #→changeで変えれる
    
    unit = (0,0)
    def f(self,x,y):
        a,b = x
        c,d = y
        return (a + c,b + d)

    #頂点は1-index、一番下の段は0-index(bitは1-index)
    def __init__(self,N):
        self.N = N
        self.X = [self.unit] * (N + N)
    def build(self,seq):
        for i,x in enumerate(seq,self.N):
            self.X[i] = x
        for i in range(self.N-1,0,-1):
            self.X[i] = self.f(self.X[i << 1],self.X[i << 1 | 1])
    def set(self,i,x):
        i += self.N
        self.X[i] = x
        while i > 1:
            i >>= 1
            self.X[i] = self.f(self.X[i << 1],self.X[i << 1 | 1])
    def fold(self,L,R):
        #区間[L,R)についてfold
        #0 <= L,R <= N にしなきゃダメ
        L += self.N
        R += self.N
        vL = self.unit
        vR = self.unit
        while L < R:
            if L & 1:
                vL = self.f(vL,self.X[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.f(self.X[R],vR)
            L >>= 1
            R >>= 1
        return self.f(vL,vR)
    def change(self,f,unit):
        self.f = f
        self.unit = unit

        

import sys
rr = sys.stdin
N,Q = map(int,rr.readline().split())
a = list(map(int,rr.readline().split()))
seg = SegTree(N)
ll = [(t,i) for i,t in enumerate(a)]
query = []
for _ in range(Q):
    s,l,r,x = map(int,rr.readline().split())
    query.append((x,l,r,_))
ll.sort(key = lambda x:x[0])
query.sort(key = lambda x:x[0],reverse = True)
ans = [0] * Q
for x,l,r,i in query:
    while ll and ll[-1][0] >= x:
        t,index = ll.pop()
        seg.set(index,(t,1))
    tmp,num = seg.fold(l-1,r)
    ans[i] = tmp - num * x

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