HDU 1698.Just a Hook-线段树(成段替换、输出总和tree[1])
HDU1698.Just a Hook
这个题是最最基础的成段更新的线段数的题目,直接贴代码吧。
代码:
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<queue>
#include<stack>
#include<map>
using namespace std;
typedef long long ll;
const int maxn=1e5+;
const int inf=0x3f3f3f3f;
const double eps=1e-;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
int tree[maxn<<],add[maxn<<];
void pushup(int rt)
{
tree[rt]=tree[rt<<]+tree[rt<<|];
}
void pushdown(int rt,int m)
{
if(add[rt]){
add[rt<<]=add[rt<<|]=add[rt];
tree[rt<<]=(m-(m>>))*add[rt];
tree[rt<<|]=(m>>)*add[rt];
add[rt]=;
}
}
void build(int l,int r,int rt)
{
add[rt]=;
tree[rt]=;
if(l==r){
return ;
} int m=(l+r)>>;
build(lson);
build(rson);
pushup(rt);
}
void update(int L,int R,int c,int l,int r,int rt)
{
if(L<=l&&r<=R){
add[rt]=c;
tree[rt]=c*(r-l+);
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);
}
int main()
{
int t,n,m;
while(~scanf("%d",&t)){
int cas=;
while(t--){
cas++;
scanf("%d%d",&n,&m);
build(,n,);
for(int i=;i<=m;i++){
int l,r,c;
scanf("%d%d%d",&l,&r,&c);
update(l,r,c,,n,);
}
printf("Case %d: The total value of the hook is %d.\n",cas,tree[]);
}
}
return ;
}
HDU 1698.Just a Hook-线段树(成段替换、输出总和tree[1])的更多相关文章
- HDU 1698 Just a Hook(线段树成段更新)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- HDU 1698 Just a Hook (线段树 成段更新 lazy-tag思想)
题目链接 题意: n个挂钩,q次询问,每个挂钩可能的值为1 2 3, 初始值为1,每次询问 把从x到Y区间内的值改变为z.求最后的总的值. 分析:用val记录这一个区间的值,val == -1表示这 ...
- HDU1698_Just a Hook(线段树/成段更新)
解题报告 题意: 原本区间1到n都是1,区间成段改变成一个值,求最后区间1到n的和. 思路: 线段树成段更新,区间去和. #include <iostream> #include < ...
- [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 线段树,区间定值,求和
Just a Hook Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1 ...
- HDU 1698 Just a Hook 线段树+lazy-target 区间刷新
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- HDU 1698 Just a Hook(线段树区间替换)
题目地址:pid=1698">HDU 1698 区间替换裸题.相同利用lazy延迟标记数组,这里仅仅是当lazy下放的时候把以下的lazy也所有改成lazy就好了. 代码例如以下: # ...
- HDU 1698 Just a Hook(线段树 区间替换)
Just a Hook [题目链接]Just a Hook [题目类型]线段树 区间替换 &题解: 线段树 区间替换 和区间求和 模板题 只不过不需要查询 题里只问了全部区间的和,所以seg[ ...
- (简单) 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 ...
随机推荐
- long转int
由int类型转换为long类型是向上转换,可以直接进行隐式转换,但由long类型转换为int类型是向下转换,可能会出现数据溢出情况: 主要以下几种转换方法,供参考: 一.强制类型转换 [java] l ...
- 【Binary Search Tree Iterator 】cpp
题目: Implement an iterator over a binary search tree (BST). Your iterator will be initialized with th ...
- python-使用pip安装第三方库报UnicodeDecodeError: 'utf8' codec can't decode byte 0xcb in position 7: invalid continuation byte 错误解决方案
在python 的安装目录下找到Lib\ntpath.py文件,找到def join(path, *paths):方法,添加如下两行语句: reload(sys) sys.setdefaultenco ...
- 易语言.开源(vip视频播放器源码)
下载链接:https://pan.baidu.com/s/1ta1Ig3LOiOka-kr5xB18kw
- 孤荷凌寒自学python那些事第一天
孤荷凌寒自学python第一天 初识python (学习过程的完整录像分享链接在文末,手写笔记图片在文末) 一种编程语言,首先是它的语言的基本架构,python总体让人耳目一新: 今天其实只接触到了它 ...
- 上手Caffe(二)
@author:oneBite本文简述如何在windows环境下,运行caffe的“hello world”例程体会适用caffe的流程:转换输入数据格式>在solver.prototxt中配置 ...
- Android5.0新特性
1.Activity转场动画 首先,把之前启动Activity的代码改成下面的写法: (如果低版本需要加注解@RequiresApi(api = Build.VERSION_CODES.LOLLIPO ...
- MVC学习笔记----@Helper标签(HelperMethod方法)和HtmlExtesion扩展
1,HtmlHelper扩展 http://www.cnblogs.com/willick/p/3428413.html http://www.cnblogs.com/zengdingding/p/5 ...
- docker搭建jira-7.11.1 + 破解
几行命令教你搭建一个jira最新版.所有步骤必不可少.破解补丁需要的请在下面留言. pull docker 镜像: jira:7.11.1(目前的最新版本) mysql:5.7 docker ...
- ubuntu服务器环境配置参考
一.基本的Linux系统命令: ls 查看当前目录下的文件及文件夹 cd /var/www/html 转换目录到/var/www/html cd abc/ddd/ 转换目录到当前目录下的abc文件夹下 ...