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

这些天之间这条边都必须$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. Xpath学习笔记

    最近复习自己上一年的课本,想起来刚学那个时候想做一个写日记的软件. 想不如做,用控制台瞎写了一个,一做就成了,没什么bug,期间使用Xpath来读数据,所以就稍微学了一下. 学习过程就这样做一点笔记, ...

  2. 驱动04.平台总线驱动模型——点亮LED灯

    1 平台总线的简介 平台总线是一种虚拟的总线,相应的设备则为platform_device,而驱动则为platform_driver.总线将设备和驱动绑定,在系统每注册一个设备的时候,会寻找与之匹配的 ...

  3. Python random模块(获取随机数)常用方法和使用例子

    random.randomrandom.random()用于生成一个0到1的随机符点数: 0 <= n < 1.0 random.uniformrandom.uniform(a, b),用 ...

  4. 解决,Incorrect table definition; there can be only one auto column and it must be defined as a key

    今天在迁移项目时,操作数据库报错: Incorrect table definition; there can be only one auto column and it must be defin ...

  5. url截取

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  6. 深入.NET平台和C#编程

    第一章  深入.NET框架 1.Microsoft.NET框架概述: 1).NET介绍 2)为什么需要.NET框架 通过如下两个问题说明为什么需要.NET框架 01,C#程序可以再不同平台(PDA,P ...

  7. CountDownLatch使用详解

    正如每个Java文档所描述的那样,CountDownLatch是一个同步工具类,它允许一个或多个线程一直等待,直到其他线程的操作执行完后再执行.在Java并发中,countdownlatch的概念是一 ...

  8. LED的串联电阻值的计算

    与LED串联的电阻被用于控制该LED导通时的电流量.为了计算电阻值,你需要知道输入电源电压(Vs,一般为5V),LED的正向电压(Vf)和你需要流过LED的电源(/)的数值. 其电阻欧姆值的计算公式( ...

  9. android .9图片制作与注意

    首先找到你的开发软件所依赖的SDK,在电脑中找到这个SDK的安装路径,如果有太多SDK分不清楚,Window→Android SDK Manager 点开可以看到你的依赖SDK路径,多余的不说直接发个 ...

  10. 报错找不到org.apache,http...的解决办法

    在build.gradle中加入 android { useLibrary 'org.apache.http.legacy' }