結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー shotoyooshotoyoo
提出日時 2022-08-20 01:43:26
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,420 ms / 4,000 ms
コード長 2,510 bytes
コンパイル時間 220 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 119,728 KB
最終ジャッジ日時 2024-05-09 17:34:02
合計ジャッジ時間 8,365 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 54 ms
55,680 KB
testcase_01 AC 53 ms
55,936 KB
testcase_02 AC 53 ms
55,936 KB
testcase_03 AC 95 ms
77,440 KB
testcase_04 AC 76 ms
72,064 KB
testcase_05 AC 95 ms
77,568 KB
testcase_06 AC 77 ms
73,088 KB
testcase_07 AC 90 ms
77,056 KB
testcase_08 AC 112 ms
81,280 KB
testcase_09 AC 114 ms
81,408 KB
testcase_10 AC 114 ms
81,664 KB
testcase_11 AC 129 ms
81,280 KB
testcase_12 AC 123 ms
81,280 KB
testcase_13 AC 576 ms
102,400 KB
testcase_14 AC 455 ms
96,000 KB
testcase_15 AC 790 ms
112,384 KB
testcase_16 AC 843 ms
112,384 KB
testcase_17 AC 694 ms
109,184 KB
testcase_18 AC 687 ms
109,056 KB
testcase_19 AC 669 ms
109,056 KB
testcase_20 AC 1,420 ms
119,728 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, random
input = lambda : sys.stdin.readline().rstrip()


write = lambda x: sys.stdout.write(x+"\n"); writef = lambda x: print("{:.12f}".format(x))
debug = lambda x: sys.stderr.write(x+"\n")
YES="Yes"; NO="No"; pans = lambda v: print(YES if v else NO); INF=10**18
LI = lambda : list(map(int, input().split())); II=lambda : int(input())
def debug(_l_):
    for s in _l_.split():
        print(f"{s}={eval(s)}", end=" ")
    print()
def dlist(*l, fill=0):
    if len(l)==1:
        return [fill]*l[0]
    ll = l[1:]
    return [dlist(*ll, fill=fill) for _ in range(l[0])]
class BIT:
    ### BIT binary
    def __init__(self, n, values=None):
        self.bit = [0]*(n+1)
        self.n = n
        self.total = 0
        if values is not None:
            for i,v in enumerate(values):
                self.add(i,v)
                self.total += v
    def check(self):
        l = []
        prv = 0
        for i in range(1,self.n+1):
            val = self.query(i)
            l.append(val-prv)
            prv = val
        print(" ".join(map(str, l)))
    #a1 ~ aiまでの和 O(logn)
    def query(self,i):
        res = 0
        while i > 0:
            res += self.bit[i]
            # res %= M
            i -= i&(-i)
        return res
    def get(self,i):
        return self.query(i+1) - self.query(i)
    #ai += x(logN)
    def add(self,i,x):
        i += 1
        if i==0:
            raise RuntimeError
        self.total += x
        while i <= self.n:
            self.bit[i] += x
            # self.bit[i] %= M
            i += i&(-i)
    def index(self, v):
        """a0,...,aiの和がv以上になる最小のindexを求める
        存在しないとき配列サイズを返す
        """
        if v <= 0:
            return 0
        if self.total<v:
            return self.n
        x = 0
        r = 1
        while r < self.n:
            r = r << 1;
        ll = r
        while ll>0:
            if x+ll<self.n and self.bit[x+ll]<v:
                v -= self.bit[x+ll]
                x += ll
            ll = ll>>1
        return x

n = int(input())
a = list(map(int, input().split()))
from collections import Counter
count = Counter(a)
kvs = list(count.items())
kvs.sort()
m = max(a)
ans = 0
c = 0
s = 0
bit = BIT(2*m+10)
for k,v in kvs[::-1]:
    ans += v*c*k
    c += v
    tmp = s
    for vv in range(k, m+1, k):
        val = bit.query(vv+k) - bit.query(vv)
        tmp -= val*vv
    ans -= tmp
    s += k*v
    bit.add(k, v)
#     print(ans, c, s)
print(ans)
0