結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー gr1msl3ygr1msl3y
提出日時 2022-08-26 23:33:53
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,291 bytes
コンパイル時間 292 ms
コンパイル使用メモリ 87,056 KB
実行使用メモリ 261,020 KB
最終ジャッジ日時 2023-08-22 11:55:00
合計ジャッジ時間 11,099 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,548 KB
testcase_01 AC 73 ms
71,692 KB
testcase_02 AC 72 ms
71,516 KB
testcase_03 AC 105 ms
78,012 KB
testcase_04 AC 102 ms
77,972 KB
testcase_05 AC 99 ms
76,968 KB
testcase_06 AC 103 ms
77,948 KB
testcase_07 AC 106 ms
77,976 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.size = n
        self.tree = [0] * (n + 1)

    def sum(self, i):
        i += 1
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s

    def sumrange(self, i, j):
        si = self.sum(i - 1)
        sj = self.sum(j)
        return sj - si

    def add(self, i, x):
        i += 1
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

    def lower_bound(self, w):
        if w <= 0:
            return 0
        x = 0
        r = 1 << (self.size).bit_length()
        while r > 0:
            if x+r < self.size and self.tree[x+r] < w:
                w -= self.tree[x+r]
                x += r
            r = r >> 1
        return x


N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7
A.sort(reverse=True)
M = int(A[0]**0.5)
bit = Bit(A[0]+2)

ans = 0
for i, a in enumerate(A):
    ans += (2*i-N+1)*a % MOD
    ans %= MOD
    if a >= M:
        v = 0
        for j in range(M+2):
            if a*j > A[0]:
                break
            ans += j*bit.sumrange(j*a, min((j+1)*a-1, A[0]))*a % MOD
            ans %= MOD
    else:
        for b in A[:i]:
            ans += b//a*a
            ans %= MOD
    bit.add(a, 1)

print(ans)
0