http://www.elijahqi.win/archives/3293
考虑这题最小割怎么建图 源向每个点连 黑的贡献 每个点向汇连白的贡献然后每个点 新建一个点 向他连p的代价 这个每个p向一段区间连 这个区间连的话就直接线段树优化建图即可 但是因为他每次都只和前面的连 所以就被强行可持久化了 写个主席树即可 每次把a当作权值插到权值线段树里即可 mmp样例太水我主席树写错了都跑的出来
#include<queue>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
using namespace std;
inline char gc(){
static char now[1<<16],*S,*T;
if (T==S){T=(S=now)+fread(now,1,1<<16,stdin);if (T==S) return EOF;}
return *S++;
}
inline int read(){
int x=0,f=1;char ch=gc();
while(!isdigit(ch)) {
if(ch=='-') f=-1;ch=gc();}
while(isdigit(ch)) x=x*10+ch-'0',ch=gc();
return x*f;
}
const int N=175000;
const int inf=0x3f3f3f3f;
int num=1,h[N],cur[N],cnt,T,rt,level[N],n,a[2000