結果

問題 No.1233 割り切れない気持ち
ユーザー ibyiby
提出日時 2020-11-28 16:43:18
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,395 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 87,152 KB
実行使用メモリ 114,648 KB
最終ジャッジ日時 2023-10-10 00:42:25
合計ジャッジ時間 18,792 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 152 ms
82,624 KB
testcase_01 AC 110 ms
82,404 KB
testcase_02 AC 206 ms
82,572 KB
testcase_03 AC 331 ms
82,740 KB
testcase_04 AC 287 ms
82,820 KB
testcase_05 AC 220 ms
82,816 KB
testcase_06 AC 241 ms
82,948 KB
testcase_07 AC 593 ms
89,336 KB
testcase_08 AC 637 ms
94,752 KB
testcase_09 AC 716 ms
106,548 KB
testcase_10 AC 726 ms
109,372 KB
testcase_11 AC 548 ms
89,004 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 179 ms
114,648 KB
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 190 ms
114,524 KB
testcase_21 AC 196 ms
112,228 KB
testcase_22 AC 192 ms
111,852 KB
testcase_23 AC 190 ms
112,184 KB
testcase_24 AC 191 ms
111,908 KB
testcase_25 AC 194 ms
112,036 KB
testcase_26 AC 191 ms
111,948 KB
testcase_27 AC 194 ms
112,184 KB
testcase_28 AC 188 ms
112,056 KB
testcase_29 AC 194 ms
112,060 KB
testcase_30 AC 189 ms
112,060 KB
testcase_31 AC 190 ms
112,456 KB
testcase_32 AC 187 ms
112,184 KB
testcase_33 AC 191 ms
112,060 KB
testcase_34 AC 184 ms
112,052 KB
testcase_35 AC 187 ms
112,092 KB
testcase_36 AC 187 ms
112,052 KB
testcase_37 AC 99 ms
82,592 KB
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

class SegTree():
    # 1-indexed
    def __init__(self, N, function, basement):
        self.n = N
        self.K = (self.n-1).bit_length()
        self.f = function
        self.b = basement
        self.seg = [basement]*(2**(self.K+1)+1)

    def update(self, k, value):
        X = 1 << (self.K)
        k += X
        self.seg[k] += value
        while k:
            k = k >> 1
            self.seg[k] = self.f(self.seg[k << 1], self.seg[(k << 1) | 1])

    def query(self, L, R):
        num = 1 << (self.K)
        L += num
        R += num
        vL = self.b
        vR = self.b
        while L < R:
            if L & 1:
                vL = self.f(vL, self.seg[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.f(self.seg[R], vR)
            L >>= 1
            R >>= 1
        return self.f(vL, vR)

def f(a,b):
    return a + b

n = int(input())
a = list(map(int, input().split()))

cash = [-1]*(200010)
segki = SegTree(200010, f, 0)
for v in a:
    segki.update(v, 1)

def get_quotient_sum(div):
    if cash[div] >= 0:
        return cash[div]
    res = 0
    for i in range(200001):
        if i*div >= 200000:
            break
        else:
            res += i*segki.query(div*i, min(div*(i + 1), 200001))
    cash[div] = res
    return res


ans = n*sum(a)
for i, v in enumerate(a):
    ans -= v*get_quotient_sum(v)
print(ans)

0