HDU 1698 Just a Hook(线段树:区间更新)
http://acm.hdu.edu.cn/showproblem.php?pid=1698
题意:
给出1~n的数,每个数初始为1,每次改变[a,b]的值,最后求1~n的值之和。
思路:
区间更新题目,关于懒惰标记什么的参考这个吧http://blog.sina.com.cn/s/blog_a2dce6b30101l8bi.html,讲得不错的。
#include<iostream>
#include<cstring>
#include<algorithm>
using namespace std; const int maxn = + ; int n, m; int col[maxn << ]; struct node
{
int l, r;
int n;
}t[maxn << ]; //如果该区间被标记了,说明该区间值改变,需要向下传递
void PushDown(int o, int m)
{
if (col[o])
{
col[o << ] = col[o << | ] = col[o];
t[o << ].n = (m - (m >> ))*col[o];
t[o << | ].n = (m >> )*col[o];
col[o] = ;
}
} void PushUp(int o)
{
t[o].n = t[o << ].n + t[o << | ].n;
} void build(int l, int r, int o)
{
col[o] = ;
t[o].l = l;
t[o].r = r;
t[o].n = ;
if (l == r) return;
int mid = (l + r) / ;
build(l, mid, * o);
build(mid + , r, * o + );
} void update(int l, int r, int x, int o)
{
if (l <= t[o].l && r >= t[o].r)
{
t[o].n = x*(t[o].r - t[o].l + );
col[o] = x;
return;
}
PushDown(o, t[o].r - t[o].l +);
int mid = (t[o].l + t[o].r) / ;
if (l > mid) update(l, r, x, * o + );
else if (r <= mid) update(l, r,x, * o);
else
{
update(l, mid, x, * o);
update(mid + , r, x, * o + );
}
//向上传递
PushUp(o);
} int main()
{
//freopen("D:\\txt.txt", "r", stdin);
int T;
int x, y, k;
int kase = ;
scanf("%d", &T);
while (T--)
{
scanf("%d", &n);
scanf("%d", &m);
build(, n, );
for (int i = ; i <= m; i++)
{
scanf("%d%d%d", &x, &y, &k);
update(x, y, k, );
}
printf("Case %d: The total value of the hook is %d.\n", kase++, t[].n);
}
}
HDU 1698 Just a Hook(线段树:区间更新)的更多相关文章
- (简单) HDU 1698 Just a Hook , 线段树+区间更新。
Description: In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of ...
- HDU 1698 Just a Hook(线段树区间更新查询)
描述 In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes ...
- HDU 1698 Just a Hook 线段树区间更新、
来谈谈自己对延迟标记(lazy标记)的理解吧. lazy标记的主要作用是尽可能的降低时间复杂度. 这样说吧. 如果你不用lazy标记,那么你对于一个区间更新的话是要对其所有的子区间都更新一次,但如果用 ...
- HDU 1698 Just a Hook(线段树 区间替换)
Just a Hook [题目链接]Just a Hook [题目类型]线段树 区间替换 &题解: 线段树 区间替换 和区间求和 模板题 只不过不需要查询 题里只问了全部区间的和,所以seg[ ...
- [HDU] 1698 Just a Hook [线段树区间替换]
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU 1698 Just a Hook(线段树区间替换)
题目地址:pid=1698">HDU 1698 区间替换裸题.相同利用lazy延迟标记数组,这里仅仅是当lazy下放的时候把以下的lazy也所有改成lazy就好了. 代码例如以下: # ...
- hdu - 1689 Just a Hook (线段树区间更新)
http://acm.hdu.edu.cn/showproblem.php?pid=1698 n个数初始每个数的价值为1,接下来有m个更新,每次x,y,z 把x,y区间的数的价值更新为z(1<= ...
- HDU.1689 Just a Hook (线段树 区间替换 区间总和)
HDU.1689 Just a Hook (线段树 区间替换 区间总和) 题意分析 一开始叶子节点均为1,操作为将[L,R]区间全部替换成C,求总区间[1,N]和 线段树维护区间和 . 建树的时候初始 ...
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- Just a Hook 线段树 区间更新
Just a Hook In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of t ...
随机推荐
- 以吃货的角度去理解云计算中On-Premise、IaaS、PaaS和SaaS
了解云计算的一定都听过四个“高大上”的概念:On-Premise(本地部署),IaaS(基础设施及服务).PaaS(平台即服务)和SaaS(软件即服务),这几个术语并不好理解.不过,如果你是个吃货,还 ...
- 【BZOJ2142】礼物 组合数+CRT
[BZOJ2142]礼物 Description 小E从商店中购买了n件礼物,打算送给m个人,其中送给第i个人礼物数量为wi.请你帮忙计算出送礼物的方案数(两个方案被认为是不同的,当且仅当存在某个人在 ...
- linux下安装F-prot杀毒软件
一. f-prot的安装 1.首先我们要创建一个带有超级权限的用户 sudo passwa root 2.su 切换用户 3.下载F-prot http://www.f-prot.com/downlo ...
- HDU 1104 Remainder(BFS 同余定理)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=1104 在做这道题目一定要对同余定理有足够的了解,所以对这道题目对同余定理进行总结 首先要明白计算机里的 ...
- 徐州网络赛F-Feature Trace【暴力】
Morgana is learning computer vision, and he likes cats, too. One day he wants to find the cat moveme ...
- IIS与ASP.NET中的线程池
1. W3 Thread Pool(W3TP) 当处于内核模式的http.sys接收到来自用户的请求之后,会将请求放入队列中.那处于用户模式的w3wp进程如何从内核模式的队列中取出请求呢?I/O完成端 ...
- python3安装后无法使用退格键的问题
# 安装readline模块 yum -y install readline-devel # 进入Python安装目录 cd /usr/python/Python- # 重新安装 ./configur ...
- Notepad++插件安装和使用和打开大文件
版权声明:本文为博主皮皮http://blog.csdn.net/pipisorry原创文章,未经博主同意不得转载. https://blog.csdn.net/pipisorry/article/d ...
- centos Linux系统日常管理2 tcpdump,tshark,selinux,strings命令, iptables ,crontab,TCP,UDP,ICMP,FTP网络知识 第十五节课
centos Linux系统日常管理2 tcpdump,tshark,selinux,strings命令, iptables ,crontab,TCP,UDP,ICMP,FTP网络知识 第十五节课 ...
- DBA-常用到的动态视图分析语句
--语句1:获取前20逻辑读取次数或逻辑写入次数或CPU 时间 ), ((CASE qs.statement_end_offset THEN DATALENGTH(qt.TEXT) ELSE qs.s ...