首先要计算出每一条路最早开始的那一天,然后最晚结束的那一天。

这些天之间这条边都必须$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的更多相关文章

  1. hdu 5861 Road 两棵线段树

    传送门:hdu 5861 Road 题意: 水平线上n个村子间有 n-1 条路. 每条路开放一天的价格为 Wi 有 m 天的操作,每天需要用到村子 Ai~Bi 间的道路 每条路只能开放或关闭一次. ( ...

  2. HDU 5861 Road 线段树区间更新单点查询

    题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5861 Road Time Limit: 12000/6000 MS (Java/Othe ...

  3. 2016 Multi-University Training Contest 10 [HDU 5861] Road (线段树:区间覆盖+单点最大小)

    HDU 5861 题意 在n个村庄之间存在n-1段路,令某段路开放一天需要交纳wi的费用,但是每段路只能开放一次,一旦关闭将不再开放.现在给你接下来m天内的计划,在第i天,需要对村庄ai到村庄bi的道 ...

  4. HDU 5861 Road (线段树)

    Road 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5861 Description There are n villages alo ...

  5. HDU 5861 Road(线段树 区间修改 单点查询)

    Road Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...

  6. HDU 5669 Road(线段树建树)(分层图最短路)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5669 [分析]线段树建树+分层图最短路 #include <cstdio> #includ ...

  7. HDU 3917 Road constructions(最小割---最大权闭合)

    题目地址:HDU 3917 这题简直神题意... 题目本身就非常难看懂不说..即使看懂了.也对这题意的逻辑感到无语...无论了.. 就依照那题意上说的做吧... 题意:给你n个城市,m个公司.若干条可 ...

  8. hdu 3917 Road constructions 最大权闭合子图

    样例说明: n(城市数目)   m(工程队数目) 每个工程队上交的税收 val[i] k(k个工程) xi   yi  ci  costi , 工程队ci承包由xi到yi,政府的补贴为costi 注意 ...

  9. hdu 5669 Road

    题目大意 \(n\)个点,\(m\)次连边 每次连边为\((a\sim b)\leftrightarrow (c\sim d),cost=w\) 即在\((a-b)\)区间内的点向\((c-d)\)区 ...

随机推荐

  1. for循环和while循环

    for循环和while循环 --道心 for循环 name1_list=['daoxin','wuxin','zhixin']for ele in name1_list: #找到"wuxin ...

  2. vmare虚拟化解决方案

    最近刚入职一家公司!主要是做vmare虚拟化的,虽然跟openstack不太沾边,但现在很多openstack都会兼容vmare程序,最终会如何我拭目以待,今天写这个也是做一个总结. 虚拟化.云计算. ...

  3. [UWP小白日记-15]在UWP手机端实时限制Textbox的输入

    说实话重来没想到验证输入是如此的苦逼的一件事情.     网上好多验证都是在输入完成后再验证,我的想法是在输入的时候就限制输入,这样我就不用再写代码来验证了 应为是手机端,所以不用判断其他非法字符,直 ...

  4. ie7,IE8不支持document.getElmentsByClassName的问题

    if (!document.getElementsByClassName) { document.getElementsByClassName = function(className, elemen ...

  5. jquery新版本不支持toggle()的解决方法

    toggle() 方法用于绑定两个或多个事件处理器函数,以响应被选元素的轮流的 click 事件. 在1.9以后官方废除了这个方法: 解决如下 在需要调用的js文件下引用 $.fn.toggle = ...

  6. C#笔记(二)变量

    C#把数据类型分为两种 ● 值类型 ● 引用类型 从概念上看:其区别是值类型直接存储其值,而引用类型存储对值的引用 这两种类型存储在内存的不同地方:值类型存储在堆栈中,而引用类型存储在托管堆上 如果变 ...

  7. CG 标准函数库

    (1)数学函数 函数 功能描述 abs(x) 返回输入参数的绝对值 acos(x) 反余切函数,输入参数范围为[-1,1], 返回[0,π]区间的角度值 all(x) 如果输入参数均不为0,则返回tu ...

  8. 学习Sass(一)

    一.什么是sass? 写过css的都知道,css是用来改变页面样式的.但它不是一种编程语言,没有变量,函数,继承等功能,只能一条条抒写样式语句很死板.在这个工具决定效率的时代,这是不能容忍的事情.怎样 ...

  9. php计算几分钟前、几小时前、几天前的几个函数分享

    /* * 精确时间间隔函数 * $time 发布时间 如 1356973323 * $str 输出格式 如 Y-m-d H:i:s * 半年的秒数为15552000,1年为31104000,此处用半年 ...

  10. ASP.NET网站怎么发布 Web项目程序怎么发布部署(暂时收藏)

    Web程序如何发布部署呢.网站项目做好了,需要发布出来,提交给客户,装上服务器.那怎么在ASP.NET开发环境中将网站程序发布出来呢 ^_^   工具/原料 Visual Studio 2010  ( ...