【CF903G】Yet Another Maxflow Problem

题意:一张图分为两部分,左边有n个点A,右边有m个点B,所有Ai->Ai+1有边,所有Bi->Bi+1有边,某些Ai->Bj有边,每条边都有一定的容量。

先要求你支持两种操作:

1.修改某条Ai->Ai+1的边的容量
2.询问从A1到Bm的最大流

n,m<=100000,流量<=10^9

题解:很有思维含量的题。

首先,我们把求最大流变成求最小割。容易发现,我们最多只会割一条Ai->Ai+1的边和一条Bi->Bi+1的边。

假设我们割掉了Ai->Ai+1的边,如果右边割掉的是Bj->Bj+1的边,那么我们还要割掉所有Ax->By的边(x<=i,y>j)。我们可以先预处理出对于每个i,最优的j是哪个。只需要从n到1枚举每个i,然后将从i连出去的边一条一条加进去,并用线段树维护区间加,全局最值即可。

由于每次只修改A的值,所以每个i选择的j是不变的,所以用堆维护一下最大值即可。

#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>
#define lson x<<1
#define rson x<<1|1
using namespace std;
const int maxn=200010;
typedef long long ll;
ll s[maxn<<2],tag[maxn<<2],f[maxn],A[maxn],B[maxn];
vector<int> C[maxn],D[maxn];
vector<int>::iterator ci,di;
int n,m,q;
struct heap
{
priority_queue<ll,vector<ll>,greater<ll> > p1,p2;
inline void erase(ll x) {p2.push(x);}
inline void push(ll x) {p1.push(x);}
inline ll top()
{
while(!p2.empty()&&p1.top()==p2.top()) p1.pop(),p2.pop();
return p1.top();
}
}p;
void build(int l,int r,int x)
{
if(l==r)
{
s[x]=B[l];
return ;
}
int mid=(l+r)>>1;
build(l,mid,lson),build(mid+1,r,rson);
s[x]=min(s[lson],s[rson]);
}
void updata(int l,int r,int x,int a,int b,int c)
{
if(a<=l&&r<=b)
{
s[x]+=c,tag[x]+=c;
return ;
}
if(tag[x]) s[lson]+=tag[x],s[rson]+=tag[x],tag[lson]+=tag[x],tag[rson]+=tag[x],tag[x]=0;
int mid=(l+r)>>1;
if(a<=mid) updata(l,mid,lson,a,b,c);
if(b>mid) updata(mid+1,r,rson,a,b,c);
s[x]=min(s[lson],s[rson]);
}
inline int rd()
{
int ret=0,f=1; char gc=getchar();
while(gc<'0'||gc>'9') {if(gc=='-') f=-f; gc=getchar();}
while(gc>='0'&&gc<='9') ret=ret*10+(gc^'0'),gc=getchar();
return ret*f;
}
int main()
{
n=rd(),m=rd(),q=rd();
int i,a;
for(i=1;i<n;i++) A[i]=rd(),B[i+1]=rd();
for(i=1;i<=m;i++) a=rd(),C[a].push_back(rd()),D[a].push_back(rd());
build(1,n,1);
for(i=1;i<=n;i++)
{
for(ci=C[i].begin(),di=D[i].begin();ci!=C[i].end();ci++,di++) updata(1,n,1,1,*ci,*di);
f[i]=s[1],p.push(A[i]+f[i]);
}
printf("%I64d\n",p.top());
for(i=1;i<=q;i++)
{
a=rd(),p.erase(A[a]+f[a]),A[a]=rd(),p.push(A[a]+f[a]);
printf("%I64d\n",p.top());
}
return 0;
}

【CF903G】Yet Another Maxflow Problem 线段树的更多相关文章

  1. Codeforces 903G Yet Another Maxflow Problem - 线段树

    题目传送门 传送门I 传送门II 传送门III 题目大意 给定一个网络.网络分为$A$,$B$两个部分,每边各有$n$个点.对于$A_{i} \ (1\leqslant i < n)$会向$A_ ...

  2. HDU 5475 An easy problem 线段树

    An easy problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...

  3. Codeforces 803G Periodic RMQ Problem 线段树

    Periodic RMQ Problem 动态开点线段树直接搞, 我把它分成两部分, 一部分是原来树上的, 一部分是后来染上去的,两个部分取最小值. 感觉有点难写.. #include<bits ...

  4. bzoj 3489 A simple rmq problem - 线段树

    Description 因为是OJ上的题,就简单点好了.给出一个长度为n的序列,给出M个询问:在[l,r]之间找到一个在这个区间里只出现过一次的数,并且要求找的这个数尽可能大.如果找不到这样的数,则直 ...

  5. spoj IITWPC4F - Gopu and the Grid Problem 线段树

    IITWPC4F - Gopu and the Grid Problem no tags  Gopu is interested in the integer co-ordinates of the ...

  6. FZU2013 A short problem —— 线段树/树状数组 + 前缀和

    题目链接:https://vjudge.net/problem/FZU-2013  Problem 2013 A short problem Accept: 356    Submit: 1083Ti ...

  7. hud-5475 An easy problem(线段树)

    http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...

  8. ZOJ-3686 A Simple Tree Problem 线段树

    题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3686 题意:给定一颗有根树,每个节点有0和1两种值.有两种操作: ...

  9. hdu 4973 A simple simulation problem. (线段树)

    题目链接 题意: 给定n长的序列 m个操作 序列默认为 1, 2, 3···n 操作1:D [l,r] 把[l,r]区间增长 :( 1,2,3,4 进行 D [1,3]变成 1,1,2,2,3,3,4 ...

随机推荐

  1. Android布局学习——android:gravity和android:layout_gravity的区别

    [Android布局学习系列]   1.Android 布局学习之——Layout(布局)详解一   2.Android 布局学习之——Layout(布局)详解二(常见布局和布局参数)   3.And ...

  2. js粘贴事件paste简单解析及遇到的坑

    在用户执行粘贴操作的时候,js能够获得剪切板的内容,本文讨论一下这个问题. 目前只有Chrome支持获取剪切板中的图片数据.还好需要这个功能的产品目前只支持Chrome和Safari,一些Chrome ...

  3. Oracle:使用二进制工具修改高版本的 exp (dump)文件,以便 低版本 imp 工具 导入

    printf "\x31" | dd of=product_2018-10-08.dmp conv=notrunc bs=1 count=1 seek=12

  4. ubuntu 12.04 右上角的网络连接图标突然消失不见

    某天Ubuntu右上角的网络连接图标突然消失不见了,右击panel -> add to panel -> Notification Area 也不管用,最关键的是上不了网了.可以在Netw ...

  5. nodejs包管理工具npm

    用Node.js安装模块 在某个项目中单独安装的时候,npm会下载所有的文件到你项目中的一个叫做node_modules的文件夹内 全局模块会被安装到{prefix}/lib/node_modules ...

  6. phonegap入门–2 Android phonegap工程建立

    一.环境要求: 需要安装Android ADT 二.支持Android相关设备列表: a)Android 2.1 (Deprecated May 2013) b)Android 2.2 c)Andro ...

  7. Mybatis -- 批量添加 -- insertBatch

    啦啦啦 ---------------InsertBatch Class : Dao /** * 批量插入perfEnvirons * * @author Liang * * 2017年4月25日 * ...

  8. linux-指定特殊域去重

    测试数据: 2017-10-24 14:14:11:1123 [ INFO] order_type=add,order_id=9152017-10-24 14:14:11:1123 [ INFO] o ...

  9. Windows 2012 R2 安装Nessus

    1.nessus官网注册 注册地址:https://www.tenable.com/products/nessus-home Name字段随意,邮箱需要填写自己的,方便接受注册码 2.注册后,登录邮箱 ...

  10. Xshell 5 免费版本安装过程

    发现本机的Xshell 5过期了用不了.在百度里搜索,下载安装后还是不可以使用.需要购买注册,后寻的一方法,分享给大家. 1.官网 进入官网,然后点击Download下方的Free License菜单 ...