Codeforces Round #537 (Div. 2)C Creative Snap (分治)
題目連結:http://codeforces.com/contest/1111/problem/C
#include<bits/stdc++.h>
using namespace std;
#define debug puts("YES");
#define rep(x,y,z) for(int (x)=(y);(x)<(z);(x)++)
#define ll long long
#define lrt int l,int r,int rt
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
#define root l,r,rt
#define mst(a,b) memset((a),(b),sizeof(a))
#define pii pair<ll,ll>
#define mk(x,y) make_pair(x,y)
const int maxn=1e5+8;
const int ub=1e6;
ll A,B;
int n,k;
ll h[maxn];
ll tmp[31];
/*
題目意思不再描述,感覺如果不是空間限制就是個線段樹的題目,
但是空間開不了這麼大,一種做法是動態開點,
還有一種就是分治處理,分治的樣子和線段樹差不多,
詳見程式碼。
*/
ll f(int nn,int s,int t,ll add){
if(nn==0){
int pos1=lower_bound(h,h+k,h[s])-h;
int pos2=upper_bound(h,h+k,h[s])-h;
return 1LL*(pos2-pos1)*B;
}
int pos=upper_bound(h+s,h+t,tmp[nn-1]+add)-h-s;///
///while(pos+1<t&&h[pos]==h[pos+1]) pos++;
if(pos==t-s){
ll val=f(nn-1,s,t,add)+A;
val=min(val,1LL*(t-s)*B*tmp[nn]);
return val;
}else if(pos==0){
ll val=f(nn-1,s,t,add+tmp[nn-1])+A;
val=min(val,1LL*(t-s)*B*tmp[nn]);
return val;
}
else return min(1LL*(t-s)*B*tmp[nn],f(nn-1,s,s+pos,add)+f(nn-1,s+pos,t,add+tmp[nn-1]));
}
int main(){
mst(h,0);
tmp[0]=1LL;rep(i,1,31) tmp[i]=tmp[i-1]*2LL;
cin>>n>>k>>A>>B;
rep(i,0,k) cin>>h[i];
sort(h,h+k);///
if(k==0) cout<<A<<'\n';
else cout<<f(n,0,k,0LL)<<'\n';
return 0;
}
相關文章
- Codeforces Round #537 (Div. 2)解題報告
- Codeforces Round #453 (Div. 2) C
- Codeforces Round #452 (Div. 2) C
- Codeforces Round 973 (Div. 2) C
- Codeforces Round 972 (Div. 2) C
- Codeforces Round #537 (Div. 2)B. Average Superhero Gang Power (貪心+暴力)
- Codeforces Round #321 (Div. 2) C DFS
- Educational Codeforces Round 33 (Rated for Div. 2) C
- Codeforces Round #323 (Div. 2) C gcdGC
- Codeforces Round #325 (Div. 2) C 模擬
- Codeforces Round #359 (Div. 2) C DFS
- Codeforces Round #290 (Div. 2) A,B,C,D
- codeforces Round #252 (Div. 2) C - Valera and Tubes
- Codeforces Round #250 (Div. 2) C、The Child and Toy
- Codeforces Round 977 (Div. 2)(B-C2)
- Codeforces Round #639 (Div. 2)
- Codeforces Round #541 (Div. 2)
- Codeforces Round #682 (Div. 2)
- Codeforces Round #678 (Div. 2)
- Codeforces Round #747 (Div. 2)
- Codeforces Round #673 (Div. 2)
- Codeforces Round #672 (Div. 2)
- Codeforces Round #448 (Div. 2) A
- Codeforces Round #217 (Div. 2)
- Codeforces Round #256 (Div. 2)
- Codeforces Round #259 (Div. 2)
- Codeforces Round #257 (Div. 2)
- Codeforces Round #258 (Div. 2)
- Codeforces Round #171 (Div. 2)
- Codeforces Round #173 (Div. 2)
- Codeforces Round 932 (Div. 2)
- Codeforces Round 934 (Div. 2)
- Codeforces Round 940 (Div. 2)
- Codeforces Round 973 (Div. 2)
- Codeforces Round 960 (Div. 2)
- Codeforces Round 958 (Div. 2)
- Codeforces Round 961 (Div. 2)
- Codeforces Round 948 (Div. 2)