結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー kotatsugamekotatsugame
提出日時 2022-08-19 21:43:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 165 ms / 4,000 ms
コード長 502 bytes
コンパイル時間 784 ms
コンパイル使用メモリ 77,684 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-09 17:20:06
合計ジャッジ時間 2,603 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
6,816 KB
testcase_01 AC 9 ms
6,944 KB
testcase_02 AC 17 ms
6,940 KB
testcase_03 AC 51 ms
6,940 KB
testcase_04 AC 36 ms
6,944 KB
testcase_05 AC 50 ms
6,940 KB
testcase_06 AC 38 ms
6,940 KB
testcase_07 AC 48 ms
6,944 KB
testcase_08 AC 7 ms
6,940 KB
testcase_09 AC 7 ms
6,940 KB
testcase_10 AC 7 ms
6,940 KB
testcase_11 AC 9 ms
6,944 KB
testcase_12 AC 8 ms
6,940 KB
testcase_13 AC 66 ms
6,940 KB
testcase_14 AC 52 ms
6,940 KB
testcase_15 AC 89 ms
6,940 KB
testcase_16 AC 93 ms
6,940 KB
testcase_17 AC 77 ms
6,940 KB
testcase_18 AC 123 ms
6,940 KB
testcase_19 AC 79 ms
6,940 KB
testcase_20 AC 165 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

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