結果
問題 |
No.2046 Ans Mod? Mod Ans!
|
ユーザー |
![]() |
提出日時 | 2022-08-21 12:47:16 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 574 ms / 4,000 ms |
コード長 | 1,192 bytes |
コンパイル時間 | 164 ms |
コンパイル使用メモリ | 82,344 KB |
実行使用メモリ | 110,096 KB |
最終ジャッジ日時 | 2024-12-16 08:35:05 |
合計ジャッジ時間 | 5,938 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
class BIT(): def __init__(self,N): self.N = N self.bit = [0] * (N + 1) def sum(self,loc): loc -= 1 res = 0 while loc: res += self.bit[loc] loc -= loc & -loc return res def sum_range(self,x,y): return self.sum(y) - self.sum(x - 1) def add(self, loc, x): while loc <= self.N: self.bit[loc] += x loc += loc & -loc def update(self,loc,x): while loc <= self.N: self.bit[loc] = x loc +=loc & -loc def binary_search(self,x): upper = self.N - 1 lower = 0 while upper - lower>1: mid = ( upper + lower) // 2 if self.sum(mid) > x - 1: upper = mid else: lower = mid return lower + 1 N = int(input()) A = list(map(int, input().split())) A.sort() Bit = BIT(3 * 10 ** 5) ans = 0 large = 0 for i in range(N)[::-1]: ans += (N - 1 - i) * A[i] ans -= large for j in range(A[i],3 * 10 ** 5, A[i]): ans += A[i] * ((N - 1 - i) - Bit.sum(j)) Bit.add(A[i], 1) large += A[i] print(ans)