传送门
看完题应该都知道是网络流了吧。
但是第二种武器直接建图会gg。
因此我们用线段树优化建图。
具体操作就是,对于这m个人先建一棵线段树,父亲向儿子连容量为inf的边,最后叶子结点向对应的人连容量为1的边。
这样给第二种武器对应连边的时候直接给区间连边就行了。
对于操作三,我们直接贪心流掉两个人,剩下的一个人不流就行了。
代码:
#include<bits/stdc++.h>
#define N 200005
#define inf 0x3f3f3f3f
#define lc (p<<1)
#define rc (p<<1|1)
#define mid (l+r>>1)
using namespace std;
inline int read(){
int ans=0;
char ch=getchar();
while(!isdigit(ch))ch=getchar();
while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
return ans;
}
bool vis[N];
int n,m,id[N],q[N],hd,tl,tot,Begin,ans,d[N],first[N],cnt,s,t;
struct edge{
int v,c,next;};
map<int,int>mp[N];
edge e[N];
inline void add(int u,int v,int c){
e[++cnt].v=v,e[cnt].c=c,e[cnt].next=first[u],first[u]=cnt;
e[++cnt].v=u,e[cnt].c=0,e[cnt].next=first[v],first[v]=cnt;
}
inline bool bfs(){
queue<int