結果

問題 No.1233 割り切れない気持ち
ユーザー ygd.
提出日時 2020-09-18 22:55:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 638 ms / 3,153 ms
コード長 989 bytes
コンパイル時間 168 ms
コンパイル使用メモリ 82,472 KB
実行使用メモリ 107,948 KB
最終ジャッジ日時 2024-06-22 19:19:36
合計ジャッジ時間 9,648 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

class BIT:
    def __init__(self, n):
        self.n = n
        self.data = [0]*(n+1)
 
    def to_sum(self, i):
        s = 0
        while i > 0:
            s += self.data[i]
            i -= (i & -i)
        return s
 
    def add(self, i, x):
        while i <= self.n:
            self.data[i] += x
            i += (i & -i)
 
    def get(self, i, j):
        return self.to_sum(j)-self.to_sum(i-1)


N = int(input())
MAX = 2*pow(10,5)+10
Tree = BIT(MAX)
A = list(map(int,input().split()))
for i in range(N):
  Tree.add(A[i],1)
S = sum(A)
MAX = max(A)
A.sort()
ans = 0
prevx = -1
for x in A:
  if x == 1:
    continue
  if x == prevx:
    ans += temp
    continue
  wari = 0; now = x; fac = 1
  for i in range(200000):
    if now+x-1 >= MAX:
      wari += Tree.get(now,MAX)*fac
      break
    else:
      wari += Tree.get(now,now+x-1)*fac
    now += x
    fac += 1
    if now > MAX + x:
      break
  #print(wari,S-wari*x)
  temp = S - wari*x
  ans += temp
  prevx = x
print(ans)

0