首页 > 其他 > 详细

D. Arpa and a list of numbers Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)

时间:2018-08-22 23:58:24      阅读:238      评论:0      收藏:0      [点我收藏+]

http://codeforces.com/contest/851/problem/D

 

分区间操作

 1 #include <cstdio>
 2 #include <cstdlib>
 3 #include <cmath>
 4 #include <cstring>
 5 #include <time.h>
 6 #include <string>
 7 #include <set>
 8 #include <map>
 9 #include <list>
10 #include <stack>
11 #include <queue>
12 #include <vector>
13 #include <bitset>
14 #include <ext/rope>
15 #include <algorithm>
16 #include <iostream>
17 using namespace std;
18 #define ll long long
19 #define minv 1e-6
20 #define inf 1e18
21 #define pi 3.1415926536
22 #define E  2.7182818284
23 const ll mod=1e9+7;//998244353
24 const int maxn=2e6+10;
25 
26 bool vis[maxn]={0};
27 ll tot[maxn]={0},sum[maxn]={0};
28 
29 int main()
30 {
31     int n,x,y,z,i,j,pos;
32     ll v,r=inf,a;
33     scanf("%d%d%d",&n,&x,&y);
34     z=x/y;
35     for (i=1;i<=n;i++)
36     {
37         scanf("%lld",&a);
38         tot[a]++;
39         sum[a]+=a;
40     }
41     for (i=1;i<=2e6;i++)
42         tot[i]+=tot[i-1],sum[i]+=sum[i-1];
43     for (i=2;i<=1e6;i++)
44         if (!vis[i])
45         {
46             v=0;
47             //(j-i,j)
48             for (j=i;j<=2e6;j+=i)
49             {
50                 pos=max(j-z,j-i+1);//[pos,j]
51                 v+= (ll)(tot[pos-1]-tot[j-i])*x + ( (ll)(tot[j]-tot[pos-1])*j-(ll)(sum[j]-sum[pos-1]) )*y;
52                 vis[j]=1;
53             }
54             r=min(r,v);
55         }
56     cout<<r;
57     return 0;
58 }

 

D. Arpa and a list of numbers Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)

原文:https://www.cnblogs.com/cmyg/p/9520915.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!