hdu1698线段树区间更新
题目链接:https://vjudge.net/contest/66989#problem/E
坑爹的线段树照着上一个线段树更新写的,结果发现有一个地方就是不对,找了半天,发现是延迟更新标记加错了!!!以后一定要小心这一点
不用query,用value【1】也能ac,但是时间要的多,不知道是为什么,明明调用函数比较慢
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define ls l,m,rt<<1
#define rs m+1,r,rt<<1|1
const int maxn=;
ll value[maxn<<],add[maxn<<];
void pushup(int rt)//向上更新
{
value[rt]=value[rt<<]+value[rt<<|];
}
void pushdown(int rt,int m)//向下更新
{
if(add[rt])
{
add[rt<<]=add[rt];//延迟标记向下更新
add[rt<<|]=add[rt];
value[rt<<]=(m-(m>>))*add[rt];//价值向下更新
value[rt<<|]=(m>>)*add[rt];
add[rt]=;//延迟标记清0
}
}
void btree(int l,int r,int rt)
{
add[rt]=;
if(l==r)
{
value[rt]=;
return ;
}
int m=(l+r)>>;
btree(ls);
btree(rs);
pushup(rt);
}
void update(int L,int R,int c,int l,int r,int rt)
{
if(L<=l&&r<=R)
{
add[rt]=c;
value[rt]=(ll)c*(r-l+);
return ;
}
pushdown(rt,r-l+);
int m=(l+r)>>;
if(L<=m)update(L,R,c,ls);
if(R>m)update(L,R,c,rs);
pushup(rt);
}
/*ll query(int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R)return value[rt];
pushdown(rt,r-l+1);
int m=(l+r)>>1;
ll ans=0;
if(L<=m)ans+=query(L,R,ls);
if(R>m)ans+=query(L,R,rs);
return ans;
}*/
int main()
{
int t,n,m;
scanf("%d",&t);
for(int i=;i<=t;i++)
{
scanf("%d%d",&n,&m);
btree(,n,);
while(m--){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
update(a,b,c,,n,);
}
printf("Case %d: The total value of the hook is %d.\n",i,value[]);
}
return ;
}
hdu1698线段树区间更新的更多相关文章
- hdu1698 线段树区间更新
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- HDU1698 线段树(区间更新区间查询)
In the game of DotA, Pudge's meat hook is actually the most horrible thing for most of the heroes. T ...
- HDU 1556 Color the ball(线段树区间更新)
Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...
- hihoCoder 1080 : 更为复杂的买卖房屋姿势 线段树区间更新
#1080 : 更为复杂的买卖房屋姿势 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi和小Ho都是游戏迷,“模拟都市”是他们非常喜欢的一个游戏,在这个游戏里面他们 ...
- HDU 5023 A Corrupt Mayor's Performance Art(线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5023 解题报告:一面墙长度为n,有N个单元,每个单元编号从1到n,墙的初始的颜色是2,一共有30种颜色 ...
- HDU 4902 Nice boat 2014杭电多校训练赛第四场F题(线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4902 解题报告:输入一个序列,然后有q次操作,操作有两种,第一种是把区间 (l,r) 变成x,第二种是 ...
- HDU 1698 线段树 区间更新求和
一开始这条链子全都是1 #include<stdio.h> #include<string.h> #include<algorithm> #include<m ...
- POJ-2528 Mayor's posters (线段树区间更新+离散化)
题目分析:线段树区间更新+离散化 代码如下: # include<iostream> # include<cstdio> # include<queue> # in ...
- ZOJ 1610 Count the Colors (线段树区间更新)
题目链接 题意 : 一根木棍,长8000,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出. 思路 :线段树区间更新一下,然后标记一下,最后从头 ...
随机推荐
- springmvc基础学习2---简单配置文件
1:web文件 2:spring-mvc.xml配置文件
- Office 365 开发概览系列文章和教程
Office 365 开发概览系列文章和教程 原文于2017年2月26日首发于LinkedIn,请参考链接 引子 之前我在Office 365技术社群(O萌)中跟大家提到,3月初适逢Visual St ...
- 计算机程序的思维逻辑 (75) - 并发容器 - 基于SkipList的Map和Set
上节我们介绍了ConcurrentHashMap,ConcurrentHashMap不能排序,容器类中可以排序的Map和Set是TreeMap和TreeSet,但它们不是线程安全的.Java并发包中与 ...
- 使用Hibernate中出现了Caused by: java.sql.SQLException: Field 'gid' doesn't have a default value
那是因为表中没有设置主键自动增长,只需要改变表中的主键设置为自动增长即可
- 隐式的处理SOAPHeader消息
先用一下比较基础的隐式方式处理我的SOAPHeader消息,注意的是QName的使用,代码如下: public static void main(String[] args) { try { //创建 ...
- 2017年要学习的JavaScript的顶级框架和主题
JavaScript的流行促进了一个非常活跃的由相关技术,框架和库组成的生态圈的发展.整个生态圈的多样性和活跃性越来越强,这让许多人变得越来越困惑. 你应该了解些什么技术呢? 我们应该将时间花费在 ...
- 共通css初次尝试
1.网页的主要的html <@fn.html css=["${basePath}/css/help/guideCommon.css${versionControl}"]tit ...
- 从spring官网下载spring 架包
1.找到spring官网地址:http://spring.io/ 2.点击projects 3.点击springframework 4.点击图片
- Javascript 闭包访问问题?
function pfajax(paradata){ $.ajax({ data : paradata.dat, type : paradata.method, async: false, url : ...
- java web中cookies的用法 转
一.什么是cookies? 大家都知道,浏览器与WEB服务器之间是使用HTTP协议进行通信的,当某个用户发出页面请求时,WEB服务器只是简单的进行响应,然后就关闭与该用户的 连接.因此当一个请求发送到 ...