Codeforces 903G 巧妙的线段树
思路:
巧妙的线段树
想方法将网络流往数据结构方向转化
http://www.cnblogs.com/yyf0309/p/8724558.html
//By SiriusRen
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=;
int n,m,q,X[N],y[N],tmp=,xx,yy;
ll tree[N<<],lazy[N<<],x[N];
struct Node{int from,to,wei;}node[N];
bool operator<(Node a,Node b){return a.from<b.from;}
void insert(int l,int r,int pos,int L,int R,ll wei){
if(l>=L&&r<=R){tree[pos]+=wei;lazy[pos]+=wei;return;}
int mid=(l+r)>>,lson=pos<<,rson=pos<<|;
if(mid<L)insert(mid+,r,rson,L,R,wei);
else if(mid>=R)insert(l,mid,lson,L,R,wei);
else insert(l,mid,lson,L,R,wei),insert(mid+,r,rson,L,R,wei);
tree[pos]=min(tree[lson],tree[rson])+lazy[pos];
}
int main(){
scanf("%d%d%d",&n,&m,&q);
for(int i=;i<=n;i++)scanf("%lld%d",&x[i-],&y[i]);
for(int i=;i<=m;i++)scanf("%d%d%d",&node[i].from,&node[i].to,&node[i].wei);
for(int i=;i<=n;i++)insert(,n,,i,i,y[i]);
sort(node+,node++m);
for(int i=;i<=n;i++){
for(;tmp<=m&&node[tmp].from<=i;tmp++)
insert(,n,,,node[tmp].to,node[tmp].wei);
X[i]=x[i],x[i]+=tree[];
}memset(tree,,sizeof(tree)),memset(lazy,,sizeof(lazy));
for(int i=;i<=n;i++)insert(,n,,i,i,x[i]);
printf("%lld\n",tree[]);
while(q--){
scanf("%d%d",&xx,&yy);
insert(,n,,xx,xx,yy-X[xx]),X[xx]=yy;
printf("%lld\n",tree[]);
}
}
Codeforces 903G 巧妙的线段树的更多相关文章
- Yet Another Maxflow Problem CodeForces - 903G (最小割,线段树)
大意: 两个n元素集合$A$, $B$, $A_i$与$A_{i+1}$连一条有向边, $B_i$与$B_{i+1}$连一条有向边, 给定$m$条从$A_i$连向$B_j$的有向边, 每次询问修改$A ...
- Buses and People CodeForces 160E 三维偏序+线段树
Buses and People CodeForces 160E 三维偏序+线段树 题意 给定 N 个三元组 (a,b,c),现有 M 个询问,每个询问给定一个三元组 (a',b',c'),求满足 a ...
- CodeForces 877E DFS序+线段树
CodeForces 877E DFS序+线段树 题意 就是树上有n个点,然后每个点都有一盏灯,给出初始的状态,1表示亮,0表示不亮,然后有两种操作,第一种是get x,表示你需要输出x的子树和x本身 ...
- [Codeforces 1197E]Culture Code(线段树优化建图+DAG上最短路)
[Codeforces 1197E]Culture Code(线段树优化建图+DAG上最短路) 题面 有n个空心物品,每个物品有外部体积\(out_i\)和内部体积\(in_i\),如果\(in_i& ...
- [Codeforces 1199D]Welfare State(线段树)
[Codeforces 1199D]Welfare State(线段树) 题面 给出一个长度为n的序列,有q次操作,操作有2种 1.单点修改,把\(a_x\)修改成y 2.区间修改,把序列中值< ...
- [Codeforces 316E3]Summer Homework(线段树+斐波那契数列)
[Codeforces 316E3]Summer Homework(线段树+斐波那契数列) 顺便安利一下这个博客,给了我很大启发(https://gaisaiyuno.github.io/) 题面 有 ...
- Codeforces Gym 100231B Intervals 线段树+二分+贪心
Intervals 题目连接: http://codeforces.com/gym/100231/attachments Description 给你n个区间,告诉你每个区间内都有ci个数 然后你需要 ...
- Codeforces 482B Interesting Array(线段树)
题目链接:Codeforces 482B Interesting Array 题目大意:给定一个长度为N的数组,如今有M个限制,每一个限制有l,r,q,表示从a[l]~a[r]取且后的数一定为q,问是 ...
- codeforces 383C Propagating tree 线段树
http://codeforces.com/problemset/problem/383/C 题目就是说, 给一棵树,将一个节点的值+val, 那么它的子节点都会-val, 子节点的子节点+val. ...
随机推荐
- python3 判断大小写
转自http://wangwei007.blog.51cto.com/68019/1134323 # 一.pyhton字符串的大小写转换, 常用的有以下几种方法: # 1.对字符串中所有字符(仅对字母 ...
- centos7在grub界面下更改root密码
想要更改root的密码或者忘记了root的密码的时候可以在grub界面下更改root的密码. 百度了很多内容,更多方法都是适用于centos6及以前版本的,终于找到一个可以的. 1.开机后,在下图界面 ...
- BZOJ 4094 USACO 2013 Dec. Optimal Milking
线段树 每个节点保存4个值,both表示左右端点都取,neither表示左右端点都不取,left表示只取左端点,right表示只取右端点. 维护的特殊姿势: $cur$的$both=max(ls.l+ ...
- CodeForcesGym 100753K Upside down primes
Upside down primes Time Limit: 2000ms Memory Limit: 262144KB This problem will be judged on CodeForc ...
- github & Front-end JavaScript frameworks
github & Front-end JavaScript frameworks https://github.com/collections/front-end-javascript-fra ...
- [luoguP1130] 红牌(DP)
传送门 幼儿园DP. ——代码 #include <cstdio> #include <iostream> ; << ); int a[MAXN][MAXN], f ...
- NEU 1351 Goagain and xiaodao's romantic story I
题目描述 Do you know goagain? If the answer is “no”, well, you can leave NEUACM. Goagain is the most per ...
- [K/3Cloud]K3Cloud的移动审批方面
基于最新的K3Cloud2的SP2,当前K3Cloud上所有的工作流都可以在移动手机上进行移动审批,具体如下: K/3 Cloud 支持移动审批,支持安卓和IOS. 关于申请试用: 1.打开浏览器,进 ...
- 写给对<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">迷惑不解的小伙伴
1.X-UA-Compatible X-UA-Compatible是自从IE8新加的一个设置,对于IE8以下的浏览器是不识别的. 通过在meta中设置X-UA-Compatible的值,可以指定网页的 ...
- jQuery中事情的动态绑定 (转)
小弟初来乍到,还弄不清楚如何添加链接 这是我转别人的,原文地址:http://blog.csdn.net/zhuyong0722/article/details/8590815#comments ...