結果
問題 | No.2065 Sum of Min |
ユーザー | ygd. |
提出日時 | 2022-09-02 22:34:01 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,209 bytes |
コンパイル時間 | 208 ms |
コンパイル使用メモリ | 81,924 KB |
実行使用メモリ | 144,308 KB |
最終ジャッジ日時 | 2024-11-16 04:42:38 |
合計ジャッジ時間 | 53,424 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 35 ms
59,716 KB |
testcase_01 | AC | 40 ms
143,248 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | TLE | - |
testcase_05 | TLE | - |
testcase_06 | TLE | - |
testcase_07 | TLE | - |
testcase_08 | TLE | - |
testcase_09 | WA | - |
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 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()