結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー titiatitia
提出日時 2022-08-21 15:52:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 741 ms / 4,000 ms
コード長 1,371 bytes
コンパイル時間 290 ms
コンパイル使用メモリ 87,172 KB
実行使用メモリ 111,820 KB
最終ジャッジ日時 2023-08-22 11:53:49
合計ジャッジ時間 8,151 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
80,660 KB
testcase_01 AC 137 ms
80,716 KB
testcase_02 AC 206 ms
80,844 KB
testcase_03 AC 413 ms
81,004 KB
testcase_04 AC 300 ms
80,968 KB
testcase_05 AC 411 ms
81,200 KB
testcase_06 AC 311 ms
81,460 KB
testcase_07 AC 388 ms
81,184 KB
testcase_08 AC 110 ms
81,500 KB
testcase_09 AC 113 ms
81,480 KB
testcase_10 AC 115 ms
81,660 KB
testcase_11 AC 120 ms
81,588 KB
testcase_12 AC 119 ms
81,432 KB
testcase_13 AC 338 ms
91,176 KB
testcase_14 AC 285 ms
88,008 KB
testcase_15 AC 460 ms
96,552 KB
testcase_16 AC 492 ms
96,712 KB
testcase_17 AC 394 ms
94,440 KB
testcase_18 AC 688 ms
94,540 KB
testcase_19 AC 387 ms
94,664 KB
testcase_20 AC 741 ms
111,820 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N=int(input())
A=sorted(map(int,input().split()))

LEN=500000

BIT=[0]*(LEN+1) # 1-indexedなtree. 配列BITの長さはLEN+1にしていることに注意。

def update(v,w): # index vにwを加える
    while v<=LEN:
        BIT[v]+=w
        v+=(v&(-v)) # v&(-v)で、最も下の立っているビット. 自分を含む大きなノードへ. たとえばv=3→v=4

def getvalue(v): # [1,v]の区間の和を求める
    ANS=0
    while v!=0:
        ANS+=BIT[v]
        v-=(v&(-v)) # 自分より小さい自分の和を構成するノードへ. たとえばv=14→v=12へ
    return ANS

def bisect_on_BIT(x): # [1,ind]の和がはじめてx以上になるindexを探す

    if x<=0:
        return 0
    
    ANS=0
    h=1<<(LEN.bit_length()-1) # LEN以下の最小の2ベキ
    while h>0:
        if ANS+h<=LEN and BIT[ANS+h]<x:
            x-=BIT[ANS+h]
            ANS+=h
        h//=2

    return ANS+1 # LENまでの和がx未満のとき, LEN+1を返すことに注意

for a in A:
    update(a,1)

SUM=sum(A)
ANS=0
for i in range(N):
    a=A[i]

    ANS+=a*(N-i-1)
    SUM-=a
    ANS-=SUM

    score=0

    for j in range(1,4*10**5):
        if j*a>2*10**5:
            break
        score+=(getvalue((j+1)*a-1)-getvalue(j*a-1))*j
        if j==1:
            score-=1

    ANS+=score*a

print(ANS)
        
    
0