# bzoj 3218: a + b Problem|最小割|主席树

``````#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN=5000+10;
const int MAXM=5000*100;
const int INF=1000000000;
int tot=1,g[MAXM],nnext[MAXM],flow[MAXM],num[MAXM];
void add(int x,int y,int z){tot++;nnext[tot]=g[x];g[x]=tot;num[tot]=y;flow[tot]=z;}
struct H{int a,b,w,l,r,p;}c[MAXN];
int n,s,t,cnt;
int ls[MAXN*3],id[MAXN*3];
bool bfs()
{
memset(d,0,sizeof(d));
team[++tail]=s;
{
for(int i=g[x];i;i=nnext[i])
if(flow[i]>0&&d[num[i]]==0)
{
d[num[i]]=d[x]+1;
team[++tail]=num[i];
}
}
if(d[t]==0) return false;
return true;
}
int dfs(int x,int mmin)
{
if(x==t) return mmin;
int f=0,tmp;
for(int i=g[x];i;i=nnext[i])
if(d[num[i]]==d[x]+1&&flow[i]>0&&(tmp=dfs(num[i],min(mmin,flow[i]))))
{
flow[i]-=tmp;
flow[i^1]+=tmp;
f+=tmp;mmin-=tmp;
if(mmin==0) return f;
}
if(f==0) d[x]=0;
return f;
}
int find(int x)
{
int l=1,r=3*n;
while(l<r)
{
int mid=(l+r)/2;
if(ls[mid]>=x) r=mid;
else l=mid+1;
}
return id[l];
}
int root[MAXN],opt;
struct HH {int l,r,num;}seg[MAXM];
void build(int &now,int last,int l,int r,int x)
{
now=++opt;
if(l==r)
{
seg[now].num=++cnt;
return ;
}
seg[now].num=++cnt;
int mid=(l+r)/2;
if(c[x].a<=mid)
{
seg[now].r=seg[last].r;
build(seg[now].l,seg[last].l,l,mid,x);
}
else
{
seg[now].l=seg[last].l;
build(seg[now].r,seg[last].r,mid+1,r,x);
}
}
void link(int now,int l,int r,int s,int t,int i)
{
if(now==0) return ;
if(s<=l&&r<=t)
{
return ;
}
int mid=(l+r)/2;
}
int main()
{
scanf("%d",&n);cnt=2*n;s=++cnt,t=++cnt;int ans=0;
for(int i=1;i<=n;i++) scanf("%d %d %d %d %d %d",&c[i].a,&c[i].b,&c[i].w,&c[i].l,&c[i].r,&c[i].p),ans+=c[i].w+c[i].b,ls[i]=c[i].l,ls[i+n]=c[i].r,ls[i+n*2]=c[i].a;