結果
問題 | No.2065 Sum of Min |
ユーザー | aaaaaaaaaa2230 |
提出日時 | 2022-09-02 22:48:05 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 774 ms / 2,000 ms |
コード長 | 1,642 bytes |
コンパイル時間 | 518 ms |
コンパイル使用メモリ | 87,296 KB |
実行使用メモリ | 108,556 KB |
最終ジャッジ日時 | 2023-08-10 05:07:04 |
合計ジャッジ時間 | 15,214 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 69 ms
71,644 KB |
testcase_01 | AC | 69 ms
71,644 KB |
testcase_02 | AC | 68 ms
71,540 KB |
testcase_03 | AC | 73 ms
71,452 KB |
testcase_04 | AC | 604 ms
108,232 KB |
testcase_05 | AC | 607 ms
108,516 KB |
testcase_06 | AC | 463 ms
108,556 KB |
testcase_07 | AC | 325 ms
107,124 KB |
testcase_08 | AC | 454 ms
106,636 KB |
testcase_09 | AC | 744 ms
106,596 KB |
testcase_10 | AC | 737 ms
107,664 KB |
testcase_11 | AC | 747 ms
107,868 KB |
testcase_12 | AC | 740 ms
106,564 KB |
testcase_13 | AC | 760 ms
106,404 KB |
testcase_14 | AC | 747 ms
106,592 KB |
testcase_15 | AC | 774 ms
106,696 KB |
testcase_16 | AC | 747 ms
106,616 KB |
testcase_17 | AC | 735 ms
106,592 KB |
testcase_18 | AC | 750 ms
106,496 KB |
testcase_19 | AC | 756 ms
106,408 KB |
testcase_20 | AC | 761 ms
106,604 KB |
testcase_21 | AC | 741 ms
106,568 KB |
ソースコード
class BIT: def __init__(self, n): self.size = n self.tree = [0]*(n+1) def build(self, list): self.tree[1:] = list.copy() for i in range(self.size+1): j = i + (i & (-i)) if j < self.size+1: self.tree[j] += self.tree[i] def sum(self, i): # [0, i) の要素の総和を返す s = 0 while i>0: s += self.tree[i] i -= i & -i return s # 0 index を 1 index に変更 転倒数を求めるなら1を足していく def add(self, i, x): i += 1 while i <= self.size: self.tree[i] += x i += i & -i # 総和がx以上になる位置のindex をbinary search def bsearch(self,x): le = 0 ri = 1<<(self.size.bit_length()-1) while ri > 0: if le+ri <= self.size and self.tree[le+ri]<x: x -= self.tree[le+ri] le += ri ri >>= 1 return le+1 n,q = map(int,input().split()) A = list(map(int,input().split())) Q = [] for i in range(q): l,r,x = map(int,input().split()) Q.append([i,l,r,x]) ans = [0]*q bit_sum = BIT(n+5) bit_num = BIT(n+5) SA = [[a,i+1] for i,a in enumerate(A)] SA.sort() Q.sort(key=lambda x: x[3]) now = 0 for ind,l,r,x in Q: while now < n and SA[now][0] <= x: a,i = SA[now] bit_sum.add(i,a) bit_num.add(i,1) now += 1 num = bit_num.sum(r+1)-bit_num.sum(l) count = bit_sum.sum(r+1)-bit_sum.sum(l) + (r-l+1-num)*x # print(l,r,x,num,count,now) ans[ind] = count for i in ans: print(i)