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,注 ...
随机推荐
- iOS - Mac OS X 终端设置
Mac OS X 终端设置 1)Finder 中显示资源库 方法一: 在 "终端" 中输入下面的命令: 显示: chflags nohidden ~/Library/ 隐藏: ch ...
- Redis的安装与部署
为了解决公司产品数据增长过快,初始化太耗费时间的问题,决定使用redis作为缓存服务器. Windows下的安装与部署: 可以直接参考这个文章,我也是实验了一遍:http://www.runoob.c ...
- text属性
-------------------------------------------------------------------------------- 对p标签进行样式的设置 text-ju ...
- [分享] WIN7x64封装体积小于4G制作过程
raymond 发表于 2015-11-1 18:27:17 https://www.itsk.com/thread-359041-1-1.html 前人栽树,后人乘凉!感谢各位大神的作品!我只是按部 ...
- python核心编程第六章练习6-10
6-10.字符串.写一个函数,返回一个跟输入字符串相似的字符串,要求字符串的大小写反转,比如,输入“Mr.Ed”,应该返回“mR.eD”作为输出.[答案]代码如下: #!/usr/bin/env py ...
- ubuntu忘记密码怎么办
刚安装了,ubuntu14.04,就想着,如果忘记登录密码,这可不好办,所以测试下开机,刚过bios显示画面,不停的点击,,键盘左边的shift键.(因为刚开始是采用按着不放的办法,结果不灵.所以我不 ...
- vue学习笔记之v-for与-repeat
今天看到一个v-repeat的例子 <body> <ul id="tags"> <li v-repeat="tags"> { ...
- 便携式文件夹加密器 lockdir 5.74
便携式文件夹加密器 lockdir 5.74下载地址 http://www.hoposoft.com/lock/ 注册码两枚: 注册名:Long 注册码:6088805000000E7E25F09A6 ...
- dpkg命令的用法
dpkg 是Debian package的简写,为”Debian“ 操作系统 专门开发的套件管理系统,用于软件的安装,更新和移除. 所有源自"Debian"的Linux的发行版都使 ...
- poj 2777
题意:两个操作:c l r x l到r之间的颜色变成x q l r 询问l到r有多少种颜色 思路:记一个整数表示哪种颜色是否取了 这里真的是煞笔了,看到这一题第一直觉是异或,但是A^A= ...