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

Posted cmyg

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了D. Arpa and a list of numbers Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)(示相关的知识,希望对你有一定的参考价值。

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)(示的主要内容,如果未能解决你的问题,请参考以下文章

codeforces 851D Arpa and a list of numbers

Codeforces 851D Arpa and a list of numbers

D. Arpa's weak amphitheater and Mehrdad's valuable Hoses 分组背包模板题

Codeforces Round #486 (Div. 3) D. Points and Powers of Two

Codeforces Round #411 (Div. 2)D. Minimum number of steps(贪心)

Codecraft-18 and Codeforces Round #458 (combined) D. Bash and a Tough Math Puzzle 线段树+二分+卡时间+优化