結果

問題 No.2046 Ans Mod? Mod Ans!
ユーザー たたき@競プロたたき@競プロ
提出日時 2023-07-10 20:24:53
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 80 ms / 4,000 ms
コード長 731 bytes
コンパイル時間 2,773 ms
コンパイル使用メモリ 243,824 KB
実行使用メモリ 7,928 KB
最終ジャッジ日時 2023-10-10 01:23:01
合計ジャッジ時間 4,462 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
7,788 KB
testcase_01 AC 24 ms
7,872 KB
testcase_02 AC 23 ms
7,756 KB
testcase_03 AC 25 ms
7,732 KB
testcase_04 AC 24 ms
7,768 KB
testcase_05 AC 24 ms
7,732 KB
testcase_06 AC 23 ms
7,736 KB
testcase_07 AC 24 ms
7,888 KB
testcase_08 AC 24 ms
7,764 KB
testcase_09 AC 26 ms
7,864 KB
testcase_10 AC 25 ms
7,828 KB
testcase_11 AC 25 ms
7,724 KB
testcase_12 AC 25 ms
7,824 KB
testcase_13 AC 47 ms
7,828 KB
testcase_14 AC 39 ms
7,856 KB
testcase_15 AC 56 ms
7,820 KB
testcase_16 AC 57 ms
7,796 KB
testcase_17 AC 52 ms
7,792 KB
testcase_18 AC 50 ms
7,760 KB
testcase_19 AC 53 ms
7,744 KB
testcase_20 AC 80 ms
7,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using pp=pair<int,int>;
#define sr string 
#define vc vector
#define db double
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define pque priority_queue
#define bpc(a) __builtin_popcount(a)
int main(){
	int n;cin>>n;
	int m=3e5;
	vc<ll>v(m,0); vc<ll>s(m,0);
	rep(i,n){
		ll a;cin>>a;
		v[a]++;
	}
	rep(i,m)s[i]=v[i]*i;
	rep(i,m-1)v[i+1]+=v[i];
	rep(i,m-1)s[i+1]+=s[i];
	ll ans=0;
	for(int i=1;i<m;i++){
		ll now=v[i]-v[i-1];
		ans+=now*(v[m-1]-v[i])*i;
		for(int j=i;j<m;j+=i){
			int nj=min(m-1,j+i-1);
			ans-=now*(s[nj]-s[j]);
			ans+=now*(v[nj]-v[j])*j;
		}
	}
	cout<<ans;
}
	
0