結果

問題 No.1233 割り切れない気持ち
ユーザー 👑 tamatotamato
提出日時 2020-09-18 22:16:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 765 ms / 3,153 ms
コード長 1,629 bytes
コンパイル時間 251 ms
コンパイル使用メモリ 87,776 KB
実行使用メモリ 111,208 KB
最終ジャッジ日時 2023-09-04 21:50:14
合計ジャッジ時間 31,350 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 666 ms
82,024 KB
testcase_01 AC 647 ms
82,024 KB
testcase_02 AC 611 ms
81,948 KB
testcase_03 AC 617 ms
81,772 KB
testcase_04 AC 666 ms
82,392 KB
testcase_05 AC 641 ms
81,976 KB
testcase_06 AC 624 ms
81,884 KB
testcase_07 AC 653 ms
88,332 KB
testcase_08 AC 682 ms
93,348 KB
testcase_09 AC 740 ms
104,820 KB
testcase_10 AC 763 ms
107,396 KB
testcase_11 AC 677 ms
87,276 KB
testcase_12 AC 765 ms
111,096 KB
testcase_13 AC 735 ms
110,988 KB
testcase_14 AC 740 ms
110,688 KB
testcase_15 AC 765 ms
110,816 KB
testcase_16 AC 725 ms
110,900 KB
testcase_17 AC 692 ms
109,524 KB
testcase_18 AC 686 ms
110,828 KB
testcase_19 AC 676 ms
111,208 KB
testcase_20 AC 709 ms
109,516 KB
testcase_21 AC 692 ms
110,652 KB
testcase_22 AC 727 ms
110,252 KB
testcase_23 AC 685 ms
110,220 KB
testcase_24 AC 695 ms
110,192 KB
testcase_25 AC 700 ms
110,216 KB
testcase_26 AC 707 ms
110,588 KB
testcase_27 AC 757 ms
110,276 KB
testcase_28 AC 698 ms
110,692 KB
testcase_29 AC 684 ms
110,852 KB
testcase_30 AC 705 ms
110,540 KB
testcase_31 AC 734 ms
110,404 KB
testcase_32 AC 735 ms
110,492 KB
testcase_33 AC 728 ms
110,696 KB
testcase_34 AC 731 ms
110,692 KB
testcase_35 AC 687 ms
110,408 KB
testcase_36 AC 706 ms
110,592 KB
testcase_37 AC 647 ms
82,048 KB
testcase_38 AC 728 ms
109,344 KB
testcase_39 AC 731 ms
110,676 KB
testcase_40 AC 711 ms
110,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 1000000007
eps = 10**-9


def main():
    import sys
    input = sys.stdin.readline

    class Bit:
        def __init__(self, n):
            self.size = n
            self.tree = [0] * (n + 1)

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

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

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

    N = int(input())
    A = list(map(int, input().split()))
    M = 200000

    bit_val = Bit(M)
    bit_num = Bit(M)
    C = [0] * (M+1)
    for a in A:
        bit_num.add(a, 1)
        bit_val.add(a, a)
        C[a] += 1
    ans = 0
    for a in range(2, M+1):
        prev_sum = 0
        prev_num = 0
        for k in range(1, M+1):
            if a * k - 1 >= M:
                S = bit_val.sum(M) - prev_sum
                NN = bit_num.sum(M) - prev_num
                ans += (S - NN * a * (k - 1)) * C[a]
                break
            S = bit_val.sum(a * k - 1) - prev_sum
            NN = bit_num.sum(a * k - 1) - prev_num
            ans += (S - NN * a * (k-1)) * C[a]
            prev_sum += S
            prev_num += NN
    print(ans)


if __name__ == '__main__':
    main()
0