結果

問題 No.2065 Sum of Min
ユーザー ShirotsumeShirotsume
提出日時 2022-09-02 22:57:11
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 666 ms / 2,000 ms
コード長 1,560 bytes
コンパイル時間 269 ms
コンパイル使用メモリ 82,060 KB
実行使用メモリ 105,024 KB
最終ジャッジ日時 2024-04-27 22:36:57
合計ジャッジ時間 13,735 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 43 ms
54,016 KB
testcase_01 AC 43 ms
54,144 KB
testcase_02 AC 43 ms
54,144 KB
testcase_03 AC 43 ms
54,272 KB
testcase_04 AC 458 ms
102,104 KB
testcase_05 AC 439 ms
104,828 KB
testcase_06 AC 440 ms
97,764 KB
testcase_07 AC 313 ms
101,288 KB
testcase_08 AC 460 ms
99,632 KB
testcase_09 AC 647 ms
102,188 KB
testcase_10 AC 645 ms
105,024 KB
testcase_11 AC 607 ms
104,420 KB
testcase_12 AC 635 ms
101,588 KB
testcase_13 AC 654 ms
101,584 KB
testcase_14 AC 643 ms
101,532 KB
testcase_15 AC 652 ms
102,296 KB
testcase_16 AC 641 ms
101,592 KB
testcase_17 AC 666 ms
102,216 KB
testcase_18 AC 666 ms
102,308 KB
testcase_19 AC 658 ms
102,032 KB
testcase_20 AC 643 ms
101,536 KB
testcase_21 AC 645 ms
102,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import sys
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(mi())
inf = 2 ** 63 - 1
mod = 998244353
class fenwick_tree():
    n=1
    data=[0 for i in range(n)]
    def __init__(self,N):
        self.n=N
        self.data=[0 for i in range(N)]

    def add(self,p,x):
        assert 0<=p<self.n,"0<=p<n,p={0},n={1}".format(p,self.n)

        p+=1
        while(p<=self.n):
            self.data[p-1]+=x
            p += p&(-p)
    def sum(self,l,r):
        assert (0<=l and l<=r and r<=self.n),"0<=l<=r<=n,l={0},r={1},n={2}".format(l,r,self.n)
        return self.sum0(r)-self.sum0(l)
    def sum0(self,r):
        s=0
        while(r>0):
            s+=self.data[r-1]
            r-=r&-r
        return s

    def __getitem__(self, p):
        if isinstance(p, int):
            return self.sum(p, p + 1)
        else:
            return self.sum(p.start, p.stop)

    def __setitem__(self, p, x):
        return self.add(p, x)

    def __str__(self) -> str:
        return str([self[i] for i in range(self.n)])
    
n, q = mi()

C = fenwick_tree(n)
a = li()
A = [(i, a[i]) for i in range(n)]
A.sort(key = lambda x: x[1], reverse=True)
S = fenwick_tree(n)
query = [[i] + li() for i in range(q)]

query.sort(key = lambda x: x[3])
ans = [0] * q

for i, l, r, x in query:
    while A and A[-1][1] <= x:
        k, a = A.pop()
        C[k] += 1
        S[k] += a
    ans[i] = S[l-1:r] + x * (r - l + 1-  C[l-1:r])


for v in ans:
    print(v)









0