結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー kotatsugamekotatsugame
提出日時 2022-08-19 21:43:34
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 169 ms / 4,000 ms
コード長 502 bytes
コンパイル時間 948 ms
コンパイル使用メモリ 76,500 KB
実行使用メモリ 6,272 KB
最終ジャッジ日時 2024-12-16 08:16:28
合計ジャッジ時間 2,773 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<algorithm>
#include<atcoder/fenwicktree>
using namespace std;
int N;
int A[2<<17];
int main()
{
	cin>>N;
	for(int i=0;i<N;i++)cin>>A[i];
	sort(A,A+N);
	atcoder::fenwick_tree<int>BIT(200001);
	atcoder::fenwick_tree<long>SUM(200001);
	long ans=0;
	for(int i=N;i--;)
	{
		ans+=(long)A[i]*(N-i-1);
		for(int k=A[i];k<=200000;k+=A[i])
		{
			int r=min(k+A[i],200001);
			ans-=SUM.sum(k,r)-BIT.sum(k,r)*(long)k;
		}
		BIT.add(A[i],1);
		SUM.add(A[i],A[i]);
	}
	cout<<ans<<endl;
}
0