結果
問題 |
No.2046 Ans Mod? Mod Ans!
|
ユーザー |
![]() |
提出日時 | 2022-08-21 12:45:48 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,241 bytes |
コンパイル時間 | 459 ms |
コンパイル使用メモリ | 82,020 KB |
実行使用メモリ | 109,952 KB |
最終ジャッジ日時 | 2024-12-16 08:34:53 |
合計ジャッジ時間 | 6,658 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 5 WA * 13 |
ソースコード
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 mod = 10 ** 9 + 7 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] ans %= mod large %= mod print(ans)