solution
线段树动态开点模板题
code
#define SiberianSquirrel return
#define CuteKiloFish 0;
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = ll(1e9 + 7);
const ll INF = ll(1e18 + 10);
const int inf = int(0x3f3f3f3f);
const int N = (int)(1e5 + 10);
/*
inline __int128 read(){
__int128 x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-')
f=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=x*10+ch-'0';
ch=getchar();
}
return x*f;
}
inline void print(__int128 x){
if(x<0){
putchar('-');
x=-x;
}
if(x>9)
print(x/10);
putchar(x%10+'0');
}
*/
//VARS
ll num[N * 50], le[N * 50], re[N * 50], t[N * 50];
ll root, cnt;
ll n, k, A, B;
void push_up(int rt, int len) {
num[rt] = num[le[rt]] + num[re[rt]];
t[rt] = min(t[le[rt]] + t[re[rt]], B * num[rt] * len);
}
void modify(ll &rt, int l, int r, int L, int R, ll v) {
if(rt == 0) rt = ++ cnt;
if(l == r) {
num[rt] ++;
t[rt] = B * num[rt] * (r - l + 1);
return ;
}
int mid = l + r >> 1;
if(v <= mid) modify(le[rt], l, mid, L, R, v);
else modify(re[rt], mid + 1, r, L, R, v);
push_up(rt, r - l + 1);
}
void solve() {
cin >> n >> k >> A >> B;
t[0] = A;
for(int i = 1; i <= k; ++ i) {
ll v; cin >> v;
modify(root, 1, (1 << n), 1, (1 << n), v);
}
cout << t[root] << endl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifdef ACM_LOCAL
freopen("input", "r", stdin);
freopen("output", "w", stdout);
signed test_index_for_debug = 1;
char acm_local_for_debug = 0;
do {
if (acm_local_for_debug == '$') exit(0);
if (test_index_for_debug > 20)
throw runtime_error("Check the stdin!!!");
auto start_clock_for_debug = clock();
solve();
auto end_clock_for_debug = clock();
cout << "Test " << test_index_for_debug << " successful" << endl;
cerr << "Test " << test_index_for_debug++ << " Run Time: "
<< double(end_clock_for_debug - start_clock_for_debug) / CLOCKS_PER_SEC << "s" << endl;
cout << "--------------------------------------------------" << endl;
} while (cin >> acm_local_for_debug && cin.putback(acm_local_for_debug));
#else
solve();
#endif
SiberianSquirrel
CuteKiloFish
}
柯
敬
仲
墨
竹
柯敬仲墨竹
柯敬仲墨竹
明
李
东
阳
明~~~~~ 李东阳
明 李东阳
莫
将
画
竹
论
难
易
,
刚
道
繁
难
简
更
难
。
莫将画竹论难易,刚道繁难简更难。
莫将画竹论难易,刚道繁难简更难。
君
看
萧
萧
只
数
叶
,
满
堂
风
雨
不
胜
寒
。
君看萧萧只数叶,满堂风雨不胜寒。
君看萧萧只数叶,满堂风雨不胜寒。