結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー chineristACchineristAC
提出日時 2022-08-19 22:15:34
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,205 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 87,080 KB
実行使用メモリ 106,464 KB
最終ジャッジ日時 2023-08-22 11:43:00
合計ジャッジ時間 7,220 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 145 ms
82,456 KB
testcase_01 AC 156 ms
82,336 KB
testcase_02 AC 191 ms
82,336 KB
testcase_03 AC 310 ms
83,036 KB
testcase_04 AC 255 ms
82,620 KB
testcase_05 AC 313 ms
83,052 KB
testcase_06 AC 258 ms
82,892 KB
testcase_07 AC 304 ms
82,496 KB
testcase_08 AC 146 ms
83,240 KB
testcase_09 AC 148 ms
83,108 KB
testcase_10 AC 150 ms
83,008 KB
testcase_11 AC 152 ms
83,276 KB
testcase_12 AC 157 ms
83,432 KB
testcase_13 WA -
testcase_14 AC 261 ms
90,508 KB
testcase_15 AC 376 ms
98,848 KB
testcase_16 WA -
testcase_17 AC 330 ms
96,840 KB
testcase_18 AC 496 ms
96,584 KB
testcase_19 WA -
testcase_20 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,random,bisect
from collections import deque,defaultdict,Counter
from heapq import heapify,heappop,heappush
from itertools import cycle, permutations
from math import log,gcd

input = lambda :sys.stdin.readline().rstrip()
mi = lambda :map(int,input().split())
li = lambda :list(mi())

class BIT():
    def __init__(self,n,mod=0):
        self.BIT = [0]*(n+1)
        self.num = n
        self.mod = mod

    """
    return A[1] + A[2] + ... A[idx] in O(log n)
    """
    def query(self,idx):
        res_sum = 0
        mod = self.mod
        while idx > 0:
            res_sum += self.BIT[idx]
            if mod:
                res_sum %= mod
            idx -= idx&(-idx)
        return res_sum

    """
    A[idx] += in O(log n)
    """
    def update(self,idx,x):
        mod = self.mod
        while idx <= self.num:
            self.BIT[idx] += x
            if mod:
                self.BIT[idx] %= mod
            idx += idx&(-idx)
        return

N = int(input())
A = li()

A.sort()

res = 0

fw = BIT(2*10**5)

for i in range(N)[::-1]:
    res += A[i] * (N-2*i-1)
    for k in range(A[i],2*10**5,A[i]):
        res += (N-i-1 - fw.query(k-1)) * A[i]
    fw.update(A[i],1)

print(res)
0