HDU 5861 Road
首先要计算出每一条路最早开始的那一天,然后最晚结束的那一天。
这些天之间这条边都必须$open$,然后就变成一个线段树区间$+val$的问题了,最后询问一个每个点的$val$是多少。
注意:数据中有$ai>bi$的情况。
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<iostream>
#include<ctime>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0);
void File()
{
freopen("D:\\in.txt","r",stdin);
freopen("D:\\out.txt","w",stdout);
} const int maxn=;
int T,n,m,w[maxn];
struct X{ int u,v; }p[maxn];
int L[maxn],R[maxn];
int s[*maxn]; void build(int l,int r,int rt)
{
s[rt]=;
if(l==r) return;
int m=(l+r)/;
build(l,m,*rt);
build(m+,r,*rt+);
} void update(int L,int R,int x,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
if(s[rt]==) s[rt]=x;
return;
} if(s[rt]!=)
{
if(s[*rt]==) s[*rt]=s[rt];
if(s[*rt+]==) s[*rt+]=s[rt];
} int m=(l+r)/;
if(L<=m) update(L,R,x,l,m,*rt);
if(R>m) update(L,R,x,m+,r,*rt+);
} int get(int pos,int l,int r,int rt)
{
if(l==r) { return s[rt]; } if(s[*rt]==) s[*rt]=s[rt];
if(s[*rt+]==) s[*rt+]=s[rt]; int m =(l+r)/;
if(l<=pos&&pos<=m) return get(pos,l,m,*rt);
else return get(pos,m+,r,*rt+);
} void ADD(int L,int R,int x,int l,int r,int rt)
{
if(L<=l&&r<=R) { s[rt]+=x; return; }
int m=(l+r)/;
if(L<=m) ADD(L,R,x,l,m,*rt);
if(R>m) ADD(L,R,x,m+,r,*rt+);
} int quary(int pos,int l,int r,int rt)
{
if(l==r) return s[rt]; if(s[rt]!=)
{
s[*rt]+=s[rt];
s[*rt+]+=s[rt];
s[rt]=;
} int m =(l+r)/;
if(l<=pos&&pos<=m) return quary(pos,l,m,*rt);
else return quary(pos,m+,r,*rt+); } int main()
{
while(~scanf("%d%d",&n,&m))
{
for(int i=; i<=n-; i++) scanf("%d",&w[i]);
for(int i=; i<=m; i++)
{
scanf("%d%d",&p[i].u,&p[i].v);
if(p[i].v<p[i].u) swap(p[i].v,p[i].u);
}
build(,n,);
for(int i=; i<=m; i++) update(p[i].u,p[i].v-,i,,n,);
for(int i=; i<=n-; i++) L[i]=get(i,,n,); build(,n,);
for(int i=m; i>=; i--) { update(p[i].u,p[i].v-,i,,n,); }
for(int i=; i<=n-; i++) R[i]=get(i,,n,); build(,m,);
for(int i=;i<=n-;i++)
{
if(L[i]==||R[i]==) continue;
ADD(L[i],R[i],w[i],,m,);
}
for(int i=;i<=m;i++) printf("%d\n",quary(i,,m,));
}
return ;
}
HDU 5861 Road的更多相关文章
- hdu 5861 Road 两棵线段树
传送门:hdu 5861 Road 题意: 水平线上n个村子间有 n-1 条路. 每条路开放一天的价格为 Wi 有 m 天的操作,每天需要用到村子 Ai~Bi 间的道路 每条路只能开放或关闭一次. ( ...
- HDU 5861 Road 线段树区间更新单点查询
题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5861 Road Time Limit: 12000/6000 MS (Java/Othe ...
- 2016 Multi-University Training Contest 10 [HDU 5861] Road (线段树:区间覆盖+单点最大小)
HDU 5861 题意 在n个村庄之间存在n-1段路,令某段路开放一天需要交纳wi的费用,但是每段路只能开放一次,一旦关闭将不再开放.现在给你接下来m天内的计划,在第i天,需要对村庄ai到村庄bi的道 ...
- HDU 5861 Road (线段树)
Road 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5861 Description There are n villages alo ...
- HDU 5861 Road(线段树 区间修改 单点查询)
Road Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submi ...
- HDU 5669 Road(线段树建树)(分层图最短路)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5669 [分析]线段树建树+分层图最短路 #include <cstdio> #includ ...
- HDU 3917 Road constructions(最小割---最大权闭合)
题目地址:HDU 3917 这题简直神题意... 题目本身就非常难看懂不说..即使看懂了.也对这题意的逻辑感到无语...无论了.. 就依照那题意上说的做吧... 题意:给你n个城市,m个公司.若干条可 ...
- hdu 3917 Road constructions 最大权闭合子图
样例说明: n(城市数目) m(工程队数目) 每个工程队上交的税收 val[i] k(k个工程) xi yi ci costi , 工程队ci承包由xi到yi,政府的补贴为costi 注意 ...
- hdu 5669 Road
题目大意 \(n\)个点,\(m\)次连边 每次连边为\((a\sim b)\leftrightarrow (c\sim d),cost=w\) 即在\((a-b)\)区间内的点向\((c-d)\)区 ...
随机推荐
- 结构-行为-样式-Jquery实现延迟加载特效(数据缓冲特效)
最近在做一个地产项目的过程中,原来用的延迟加载的插件在IE下会使浏览器突然缩小,这个让客户很不满意,于是就考虑到兼容性的问题决定自己写一个插件.思路:定义一个代码块,手动加载到页面,然后手动删除. ...
- Maven之pom.xml 配置详解
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- 如何在标题栏的title前添加网站logo
之前在哪个网上看到的,今天没事给写下来了: 1.将像素大小为16*16的图片命名为 favicon.ico,(图片使用的颜色好像不能超过16色),放到网站根目录下就可以了; 2.在head标签中添加代 ...
- codevs1002搭桥(prim)
题目描述: 这是道题题意有点迷(或者是我语文不好),但其实实际上求的就是图中连通块的个数,然后在连通块与连通块之间连边建图跑最小生成树.但是--这个图可能是不连通的--求桥的数量和总长 于是我立刻想到 ...
- ShopNC_WAP
记录 ShopNC_WAP 端点点滴滴 插件记录 1. http://www.jiawin.com/swipe-mobile-touch-slider swiper 插件 2. https:// ...
- CentOS 6.5安装之后的网络配置
CentOS 6.5安装之后的网络配置 1.查看IP地址,得到只有一个回环地址 127.0.0.1 2.进行网络测试,现在来测试下,看能不能ping通外网www.baidu.com 下面的是,关于pi ...
- linux中如何查看某一进程的启动时间
mark下: ps -p PID -o lstart 其中PID是进程的pid ps的参数好多啊,够摸索一下了
- NTSC色域(CIE1931)计算公式
色域(CIE1931)=ABS(RC[-6]*RC[-3]+RC[-4]*RC[-1]+RC[-2]*RC[-5]-RC[-6]*RC[-1]-RC[-4]*RC[-5]-RC[-2]*RC[-3]) ...
- 实现自己的JDBC框架
使用JDBC操作数据库时,dao层的增删改查有很多重复的代码,比如下面的 public int getTotal() { Connection conn = null;//通用代码 PreparedS ...
- Python快捷键
IDLE默认不能显示行号,使用ALT+G 跳到对应行号,在右下角有显示光标所在行.列. ALT+P 上一个历史输入内容. ALT+N 下一个历史输入内容. IDLE中按F5可以运行代码.