kuangbin_SegTree E (HDU 1698)
POJ服务器炸了 还没好呢
然后就只能跳掉一些题目了
这题也是成段更新模板题 本来lazy标记不是很明白 后来学长上课讲了一下就知道原理了 回去看看代码很容易就理解了
#include <cstdio>
#include <cstring>
#include <queue>
#include <vector>
#include <algorithm>
#define INF 0x3f3f3f3f
#define lson l, m, rt << 1
#define rson m+1, r, rt << 1 | 1
using namespace std;
typedef long long LL; const int MAXN = 1e5 + ;
LL col[MAXN<<], sum[MAXN<<]; inline void pushup(int rt)
{
sum[rt] = sum[rt<<] + sum[rt<<|];
}
inline void pushdown(int rt, int len)
{
if(col[rt]){
col[rt<<] = col[rt];
col[rt<<|] = col[rt];
sum[rt<<] = (len - (len>>)) * col[rt];
sum[rt<<|] = (len>>) * col[rt];
col[rt] = ;
}
} void build(int l, int r, int rt)
{
col[rt] = ;
if(l == r){
sum[rt] = ;
return;
}
int m = (l + r) >> ;
build(lson);
build(rson);
pushup(rt);
} void update(int L, int R, LL c, int l, int r, int rt)
{
if(L <= l && R >= r){
//printf("Update %d - %d\n", l, r);
col[rt] = c;
sum[rt] = (r - l + ) * c;
return;
}
pushdown(rt, r - l + );
int m = (l + r) >> ;
if(L <= m) update(L, R, c, lson);
if(R > m) update(L, R, c, rson);
pushup(rt);
} LL query(int L, int R, int l, int r, int rt)
{
if(L <= l && R >= r){
return sum[rt];
}
pushdown(rt, r - l + );
int m = (l + r) >> ;
LL res = ;
if(L <= m) res += query(L, R, lson);
if(R > m) res += query(L, R, rson);
return res;
} int main()
{
int t, n, q;
scanf("%d", &t);
for(int kase = ; kase <= t; kase++){
scanf("%d%d", &n, &q);
build(, n, );
while(q--){
int l, r;
LL c;
scanf("%d%d%I64d", &l, &r, &c);
update(l, r, c, , n, );
}
printf("Case %d: The total value of the hook is %I64d.\n",
kase, query(, n, , n, ));
}
return ;
}
kuangbin_SegTree E (HDU 1698)的更多相关文章
- HDU 1698 Just a Hook (线段树区间更新)
题目链接 题意 : 一个有n段长的金属棍,开始都涂上铜,分段涂成别的,金的值是3,银的值是2,铜的值是1,然后问你最后这n段总共的值是多少. 思路 : 线段树的区间更新.可以理解为线段树成段更新的模板 ...
- HDU 1698 just a hook - 带有lazy标记的线段树(用结构体实现)
2017-08-30 18:54:40 writer:pprp 可以跟上一篇博客做个对比, 这种实现不是很好理解,上一篇比较好理解,但是感觉有的地方不够严密 代码如下: /* @theme:segme ...
- HDU 1698 【线段树,区间修改 + 维护区间和】
题目链接 HDU 1698 Problem Description: In the game of DotA, Pudge’s meat hook is actually the most horri ...
- HDU 1698——Just a Hook——————【线段树区间替换、区间求和】
Just a Hook Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- HDU 1698 Just a Hook(线段树区间替换)
题目地址:pid=1698">HDU 1698 区间替换裸题.相同利用lazy延迟标记数组,这里仅仅是当lazy下放的时候把以下的lazy也所有改成lazy就好了. 代码例如以下: # ...
- Just a Hook (HDU 1698) 懒惰标记
Just a Hook (HDU 1698) 题链 每一次都将一个区间整体进行修改,需要用到懒惰标记,懒惰标记的核心在于在查询前才更新,比如将当前点rt标记为col[rt],那么此点的左孩子和右孩子标 ...
- hdu 1698 线段树成段更新
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698 #include <cstdio> #include <cmath> # ...
- HDU 1698 Just a Hook(线段树成段更新)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1698 题目: Problem Description In the game of DotA, P ...
- hdu 1698+poj 3468 (线段树 区间更新)
http://acm.hdu.edu.cn/showproblem.php?pid=1698 这个题意翻译起来有点猥琐啊,还是和谐一点吧 和涂颜色差不多,区间初始都为1,然后操作都是将x到y改为z,注 ...
随机推荐
- 用Python编写的第一个回测程序
用Python编写的第一个回测程序 2016-08-06 def savfig(figureObj, fn_prefix1='backtest8', fn_prefix2='_1_'): import ...
- C语言输出时的各种%
d 以十进制形式输出带符号整数(正数不输出符号) o 以八进制形式输出无符号整数(不输出前缀O) x 以十六进制形式输出无符号整数(不输出前缀OX) u 以十进制形式输出无符号整数 f 以小 ...
- label for
一般我们在使用radio 时都是结合label来使用的 <label><input type=”radio” name=”radio” value=’0’/>男</l ...
- 樱花漫地集于我心,蝶舞纷飞祈愿相随 训练:a preparation 训练:a preparation
知识点: 分 ...
- angularJS 报错: [ngModel:numfmt] http://errors.angularjs.org/1.4.1/ngModel/numfmt?p0=333
<!doctype html> <html ng-app="a10086"> <head> <meta charset="utf ...
- jquery 获取下拉框值与select text
下面先介绍了很多jquery获取select属性的方法,同时后面的实例我们讲的是jquery 获取下拉框值与select text代码. 下面先介绍了很多jquery获取select属性的方法,同时后 ...
- SqlServer调用CLR服务
作用 从数据库发起对外部服务的请求. 应用场景 心跳监测 定时启动站点 服务实现 代码部分(C#) using System; using System.Net; publicpartialclass ...
- NSURLCache 和 NSCache 的区别
NSURLCache 和 NSCache 的区别 NSURLCache提供的是URL Request缓存,可以在Memory和Disk上:NSCache提供了HTTP Request外的东西的缓存方式 ...
- [蟒蛇菜谱] Python方便使用的级联进度信息
class StepedProgress: '''方便显示进度的级联进度信息. ''' def __init__(self, stockPercent=[1], parentProgress=None ...
- zookeeper初识之原理
ZooKeeper 是一个分布式的,开放源码的分布式应用程序协调服务,它包含一个简单的原语集,分布式应用程序可以基于它实现同步服务,配置维护和命名服务等. Zookeeper是hadoop的一个子项目 ...