結果
問題 | No.2065 Sum of Min |
ユーザー | ygd. |
提出日時 | 2022-09-03 21:59:10 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 2,300 bytes |
コンパイル時間 | 335 ms |
コンパイル使用メモリ | 82,140 KB |
実行使用メモリ | 143,860 KB |
最終ジャッジ日時 | 2024-11-17 13:34:11 |
合計ジャッジ時間 | 48,908 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 30 ms
143,860 KB |
testcase_01 | AC | 32 ms
60,432 KB |
testcase_02 | AC | 33 ms
59,488 KB |
testcase_03 | AC | 32 ms
142,968 KB |
testcase_04 | TLE | - |
testcase_05 | TLE | - |
testcase_06 | TLE | - |
testcase_07 | TLE | - |
testcase_08 | TLE | - |
testcase_09 | AC | 125 ms
90,412 KB |
testcase_10 | TLE | - |
testcase_11 | TLE | - |
testcase_12 | TLE | - |
testcase_13 | TLE | - |
testcase_14 | TLE | - |
testcase_15 | TLE | - |
testcase_16 | TLE | - |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
ソースコード
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()