結果

問題 No.2065 Sum of Min
ユーザー ShirotsumeShirotsume
提出日時 2022-09-02 22:57:11
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 699 ms / 2,000 ms
コード長 1,560 bytes
コンパイル時間 496 ms
コンパイル使用メモリ 87,352 KB
実行使用メモリ 106,472 KB
最終ジャッジ日時 2023-08-10 05:17:37
合計ジャッジ時間 14,397 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 85 ms
71,740 KB
testcase_01 AC 85 ms
71,792 KB
testcase_02 AC 85 ms
71,908 KB
testcase_03 AC 86 ms
71,840 KB
testcase_04 AC 459 ms
98,880 KB
testcase_05 AC 444 ms
101,384 KB
testcase_06 AC 494 ms
99,128 KB
testcase_07 AC 372 ms
103,180 KB
testcase_08 AC 483 ms
101,008 KB
testcase_09 AC 676 ms
101,052 KB
testcase_10 AC 645 ms
106,472 KB
testcase_11 AC 631 ms
105,576 KB
testcase_12 AC 658 ms
100,532 KB
testcase_13 AC 661 ms
100,528 KB
testcase_14 AC 664 ms
100,516 KB
testcase_15 AC 684 ms
100,500 KB
testcase_16 AC 648 ms
100,296 KB
testcase_17 AC 683 ms
100,652 KB
testcase_18 AC 699 ms
101,236 KB
testcase_19 AC 677 ms
101,368 KB
testcase_20 AC 647 ms
100,432 KB
testcase_21 AC 667 ms
100,812 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