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 树状 ...
随机推荐
- 数据结构:二维ST表
POJ2019 我们其实是很有必要把ST算法拓展到二维的,因为二维的RMQ问题还是不少的 int N,B,K; ]; int val[maxn][maxn]; ][]; ][]; 这里的N是方阵的长宽 ...
- HDU 5533Dancing Stars on Me 基础几何
Problem Description The sky was brushed clean by the wind and the stars were cold in a black sky. Wh ...
- Asp.net Web Api 2 FORM Authentication Demo
最近看了一点 web api 2方面的书,对认证都是简单介绍了下,所以我在这里做个简单Demo,本文主要是FORM Authentication,顺带把基本认证也讲了. Demo 一.FORM Aut ...
- Item 29 优先考虑类型安全的异构容器
集合API展示了泛型的一般用法.但是它们(Set,HashMap,Map)限制了每个容器只能有固定数目的类型参数. 比如Set集合,HashMap集合: import java.util.Ha ...
- 【BZOJ4864】神秘物质 [Splay]
神秘物质 Time Limit: 10 Sec Memory Limit: 256 MB Description Input Output Sample Input Sample Output 1 ...
- 正则表达式实现将html文本转换为纯文本格式(将html字符串转换为纯文本方法)
Regex regex = new Regex("<.+?>", RegexOptions.IgnoreCase); string strOutput = regex. ...
- 老生常谈-Activity(山东数漫江湖)
对于activity的七个声生命周期回调,总是被大家翻来覆去的说,甚至说的都有些厌烦了,这部分知识虽然基础但也很重要,谁都不想在面试的时候只说出个一知半解,下面的分析是对阅读<安卓开发艺术探索& ...
- python初步学习-python数据类型之number(数值)
数据类型之 Number python number 数据类型用于存储数值. 数据类型是不容许改变的. 这就意味着如果改变 number 数据类型的值,将重新分配内存空间. python支持四种不同数 ...
- 2、MySQL常见数据库引擎及比较?
MySQL存储引擎简介 MySQL支持数个存储引擎作为对不同表的类型的处理器.MySQL存储引擎包括处理事务安全表的引擎和处理非事务安全表的引擎: MyISAM管理非事务表.它提供高速存储和检索,以及 ...
- 用python玩微信(聊天机器人,好友信息统计)
1.用 Python 实现微信好友性别及位置信息统计 这里使用的python3+wxpy库+Anaconda(Spyder)开发.如果你想对wxpy有更深的了解请查看:wxpy: 用 Python 玩 ...