結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー kotatsugamekotatsugame
提出日時 2022-08-19 21:43:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 174 ms / 4,000 ms
コード長 502 bytes
コンパイル時間 729 ms
コンパイル使用メモリ 76,864 KB
実行使用メモリ 6,292 KB
最終ジャッジ日時 2023-08-22 11:39:50
合計ジャッジ時間 2,886 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 7 ms
5,332 KB
testcase_01 AC 10 ms
5,384 KB
testcase_02 AC 20 ms
5,388 KB
testcase_03 AC 57 ms
5,456 KB
testcase_04 AC 39 ms
5,356 KB
testcase_05 AC 56 ms
5,496 KB
testcase_06 AC 41 ms
5,456 KB
testcase_07 AC 53 ms
5,340 KB
testcase_08 AC 7 ms
5,316 KB
testcase_09 AC 7 ms
5,308 KB
testcase_10 AC 7 ms
5,496 KB
testcase_11 AC 8 ms
5,472 KB
testcase_12 AC 8 ms
5,504 KB
testcase_13 AC 68 ms
5,580 KB
testcase_14 AC 54 ms
5,648 KB
testcase_15 AC 94 ms
5,820 KB
testcase_16 AC 101 ms
5,600 KB
testcase_17 AC 83 ms
5,720 KB
testcase_18 AC 131 ms
5,600 KB
testcase_19 AC 81 ms
5,632 KB
testcase_20 AC 174 ms
6,292 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