HDU 5861 Road(线段树 区间修改 单点查询)
Road
Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1132 Accepted Submission(s): 309
We know the transport plan in the next m days, each day there is one cargo need to transport from village ai to village bi, and you need to guarantee that the segments between ai and bi are open in the i-th day. Your boss wants to minimize the total cost of the next m days, and you need to tell him the charge for each day.
(At the beginning, all the segments are closed.)
1 2 3
1 3
3 4
2 4
5
5
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define met(a,b) memset(a,b,sizeof a)
#define inf 10000000
using namespace std;
typedef long long ll;
typedef pair<int,int>pii;
const int N = 4e5+;
const double eps = 1e-;
int n,sum[*N],m;
int lazy[*N],a[N],mi[N*],ma[N*];
vector<int>st[N],en[N];
struct man{
int u,v;
}q[N];
void init(){
for(int i=;i<N;i++){
st[i].clear();
en[i].clear();
}
}
void pushDown(int pos){
if(mi[pos]!=inf){
mi[pos*]=min(mi[pos*],mi[pos]);
mi[pos*+]=min(mi[pos*+],mi[pos]);
}
if(ma[pos]!=){
ma[pos*]=max(ma[pos*],ma[pos]);
ma[pos*+]=max(ma[pos*+],ma[pos]);
}
return;
} void update(int L,int R,int val,int l,int r,int pos) {
if(l>=L&&r<=R) {
mi[pos]=min(mi[pos],val);
ma[pos]=max(ma[pos],val);
return;
}
int mid=(l+r)>>;
pushDown(pos);
if(L<=mid) update(L,R,val,l,mid,pos<<);
if(mid<R)update(L,R,val,mid+,r,pos<<|);
}
void query(int l,int r,int pos) {
if(l==r){
if(mi[pos]!=inf)st[mi[pos]].pb(l);
if(ma[pos]!=)en[ma[pos]+].pb(l);
return;
}
int mid=(l+r)>>;
pushDown(pos);
query(l,mid,pos<<);
query(mid+,r,pos<<|);
return;
}
void build(int l,int r,int pos){
mi[pos]=inf;
ma[pos]=;
if(l==r){
return;
}
int mid=(l+r)/;
build(l,mid,pos*);
build(mid+,r,pos*+);
}
int main() {
int ll,rr,cnt=;
while(~scanf("%d%d",&n,&m)){
init();
build(,n-,);
for(int i=;i<n;i++){
scanf("%d",&a[i]);
}
for(int i=;i<=m;i++){
scanf("%d%d",&q[i].u,&q[i].v);
if(q[i].u>q[i].v)swap(q[i].u,q[i].v);
update(q[i].u,q[i].v-,i,,n-,);
}
query(,n-,);
int ans=;
for(int i=;i<=m;i++){
for(int x:st[i]){
ans+=a[x];
}
for(int x:en[i]){
ans-=a[x];
}
printf("%d\n",ans);
}
}
return ;
}
HDU 5861 Road(线段树 区间修改 单点查询)的更多相关文章
- HDU 5861 Road 线段树区间更新单点查询
题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5861 Road Time Limit: 12000/6000 MS (Java/Othe ...
- D - Mayor's posters POJ - 2528 离散化+线段树 区间修改单点查询
题意 贴海报 最后可以看到多少海报 思路 :离散化大区间 其中[1,4] [5,6]不能离散化成[1,2] [2,3]因为这样破坏了他们的非相邻关系 每次离散化区间 [x,y]时 把y+1点也加入 ...
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- ZOJ 1610 Count the Colors【题意+线段树区间更新&&单点查询】
任意门:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=1610 Count the Colors Time Limit: 2 ...
- hdu 1166 敌兵布阵 线段树区间修改、查询、单点修改 板子题
题目链接:敌兵布阵 题目: C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视 ...
- POJ 3468 A Simple Problem with Integers(线段树区间修改及查询)
Description You have N integers, A1, A2, ... , AN. You need to deal with two kinds of operations. On ...
- ZOJ 1610 Count the Colors(线段树,区间覆盖,单点查询)
Count the Colors Time Limit: 2 Seconds Memory Limit: 65536 KB Painting some colored segments on ...
- POJ 2528 Mayor's posters(线段树,区间覆盖,单点查询)
Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 45703 Accepted: 13239 ...
- 【树状数组区间修改单点查询+分组】HDU 4267 A Simple Problem with Integers
http://acm.hdu.edu.cn/showproblem.php?pid=4267 [思路] 树状数组的区间修改:在区间[a, b]内更新+x就在a的位置+x. 然后在b+1的位置-x 树状 ...
随机推荐
- windows修改文件的修改或者创建时间
https://www.online-tech-tips.com/computer-tips/how-to-change-the-last-modified-date-creation-date-an ...
- CSS(Cascading Style Shee)
1.CSS是Cascading Style Sheet这个几个英文单词的缩写,翻译成中文是“层叠样式表”的意思 CSS能让网页制作者有效的定制.改善网页的效果. CSS是对HTML的补充,网页设计师曾 ...
- ImageView设置边框 以及内部图片居中显示 在AndroidStudio中添加shape.xml文件
效果如图 边框设置:shape文件 <shape xmlns:android="http://schemas.android.com/apk/res/android"> ...
- Ribbon的主要组件与工作流程
一:Ribbon是什么? Ribbon是Netflix发布的开源项目,主要功能是提供客户端的软件负载均衡算法,将Netflix的中间层服务连接在一起.Ribbon客户端组件提供一系列完善的配置项如连接 ...
- AlertDialog.Builder 显示为白色 蓝色字
AlertDialog.Builder dialog = new AlertDialog.Builder( getActivity(),AlertDialog.THEME_HOLO_LIGHT);
- 图论-强连通分量-Tarjan算法
有关概念: 如果图中两个结点可以相互通达,则称两个结点强连通. 如果有向图G的每两个结点都强连通,称G是一个强连通图. 有向图的极大强连通子图(没有被其他强连通子图包含),称为强连通分量.(这个定义在 ...
- git - 开发者电脑与服务器的配置
首先公司要有一台git服务器,现在一般都托管在github服务器上,在中国可能会托管到oschina上,oschina有一点好处就是可以免费托管私有项目,而在github上想要托管自己的项目是收费的, ...
- 流程控制--while
/* while 是在有条件控制的情况下 进行的循环 */ [root@localhost test1]# vim .py //ADD #!/usr/bin/python n = while True ...
- 数据库SQL实战(1)
1.查找最晚入职员工的所有信息: CREATE TABLE `employees` ( `emp_no` int(11) NOT NULL, `birth_date` date NOT NULL, ` ...
- .NET Core 2.0.5安装具体步骤
.NET Core 2.0.5 comprises: .NET Core Runtime 2.0.5 .NET Core SDK 2.1.4 SDK Installer SDK Binaries ...