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,然后分别在不同的区间涂上不同的颜色,问你最后能够看到多少颜色,然后每个颜色有多少段,颜色大小从头到尾输出. 思路 :线段树区间更新一下,然后标记一下,最后从头 ...
随机推荐
- C++基础——C面向过程与C++面向对象编程01_圆面积求解
#include "iostream";//包含C++的头文件using namespace std;//使用命名空间std标准的命名空间(在这个命名空间中定义了很多标准定义)vo ...
- 【转】SQL Server海量数据库的索引、查询优化及分页算法
探讨如何在有着1000万条数据的MS SQL SERVER数据库中实现快速的数据提取和数据分页.以下代码说明了我们实例中数据库的“红头文件”一表的部分数据结构: CREATE TABLE [dbo]. ...
- SpringMVC REST 风格请求介绍及简单实践
简介 REST 即 Representational State Transfer.(资源)表现层状态转化.是目前最流行的一种互联网软件架构.它结构清晰.符合标准.易于理解.扩展方便,所以正得到越来越 ...
- linux vi hjkl由来
很远原因来自历史 I was reading about vim the other day and found out why it used hjkl keys as arrow keys. Wh ...
- CSS3 transition 浏览器兼容性
1.兼容性 根据canius(http://caniuse.com/#search=transition),transition 兼容性如下图所示: <!DOCTYPE html> < ...
- xgboost-python参数深入理解
由于在工作中应用到xgboost做特征训练预测,因此需要深入理解xgboost训练过程中的参数的意思和影响. 通过search,https://www.analyticsvidhya.com/blog ...
- ELK整体方案
# ELK日志搜集平台解决方案---------1. 硬件设备2. 系统环境3. elasticsearch 集群部署4. kibana 部署5. logstash 部署6. filebeat 部署7 ...
- SearchBar简单展示
import UIKit class SearchViewController: UIViewController,UISearchBarDelegate { let SCREEN_WIDTH = U ...
- body全屏
html, body { min-height: 100%; }
- 1129: 零起点学算法36——3n+1问题
1129: 零起点学算法36--3n+1问题 Time Limit: 1 Sec Memory Limit: 64 MB 64bit IO Format: %lldSubmitted: 4541 ...