結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー asumo0729asumo0729
提出日時 2022-08-21 12:45:48
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,241 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 86,940 KB
実行使用メモリ 111,672 KB
最終ジャッジ日時 2023-08-22 11:53:04
合計ジャッジ時間 6,760 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 101 ms
78,940 KB
testcase_01 AC 116 ms
79,028 KB
testcase_02 AC 166 ms
79,024 KB
testcase_03 AC 308 ms
79,564 KB
testcase_04 AC 238 ms
79,456 KB
testcase_05 AC 305 ms
79,572 KB
testcase_06 AC 249 ms
79,616 KB
testcase_07 AC 299 ms
79,676 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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)
0