結果

問題 No.2065 Sum of Min
ユーザー ygd.ygd.
提出日時 2022-09-02 22:50:44
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,300 bytes
コンパイル時間 191 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 91,292 KB
最終ジャッジ日時 2024-04-27 22:29:37
合計ジャッジ時間 4,763 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
60,380 KB
testcase_01 AC 38 ms
54,020 KB
testcase_02 AC 39 ms
53,132 KB
testcase_03 AC 38 ms
52,856 KB
testcase_04 TLE -
testcase_05 TLE -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline
#input = sys.stdin.buffer.readline #文字列はダメ
#sys.setrecursionlimit(1000000)
import bisect
#import itertools
#import random
#from heapq import heapify, heappop, heappush
#from collections import defaultdict 
#from collections import deque
#import copy #DeepCopy: hoge = [_[:] for _ in hogehoge]
import math
#from functools import lru_cache
#@lru_cache(maxsize=None)
#MOD = pow(10,9) + 7
MOD = 998244353
#dx = [1,0,-1,0]
#dy = [0,1,0,-1]
#dx8 = [1,1,0,-1,-1,-1,0,1]
#dy8 = [0,1,1,1,0,-1,-1,-1]

def main():
    N,Q = map(int,input().split())
    A = list(map(int,input().split()))
    bucketSize = int(N**(0.5))
    bucketNumber = N//bucketSize
    bucket = []
    bucketCumsum = []
    i = 0
    for bi in range(bucketNumber):
        temp = []
        for i in range(bucketSize):
            temp.append(A[bi*bucketSize + i])
        temp.sort()
        tempcumsum = [0]
        for i in range(bucketSize):
            tempcumsum.append(tempcumsum[-1] + temp[i])
        bucket.append(temp)
        bucketCumsum.append(tempcumsum)
    if N%bucketSize != 0:
        temp = []
        for i in range(N%bucketSize):
            temp.append(A[bucketSize*bucketNumber + i])
        bucket.append(temp)
        bucketNumber += 1
    
    # print(bucketCumsum)
    # print(bucket)

    for _ in range(Q):
        L,R,X = map(int,input().split())
        L -= 1; R -= 1 #0-index
        if L == R:
            ans = min(X,A[L])
            print(ans)
            continue
        ans = 0
        while L < R and L%bucketSize != 0:
            ans += min(X,A[L])
            L += 1
        while L < R and R%bucketSize != bucketSize-1:
            ans += min(X,A[R])
            R -= 1
        
        if L == R:
            print(ans)
            continue
        
        # print("LR",L,R,"ans",ans)
        left = L//bucketSize
        right = (R+1)//bucketSize
        # print("leftright",left,right)
        for bi in range(left,right):
            bucketList = bucket[bi]
            boundary = bisect.bisect_right(bucketList, X)
            # print("boundary",boundary)
            temp = bucketCumsum[bi][boundary] + (bucketSize - boundary) * X
            ans += temp
        print(ans)



    
                

if __name__ == '__main__':
    main()
0