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])的更多相关文章

  1. HDU 1698 Just a Hook(线段树成段更新)

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  2. HDU 1698 Just a Hook (线段树 成段更新 lazy-tag思想)

    题目链接 题意: n个挂钩,q次询问,每个挂钩可能的值为1 2 3,  初始值为1,每次询问 把从x到Y区间内的值改变为z.求最后的总的值. 分析:用val记录这一个区间的值,val == -1表示这 ...

  3. HDU1698_Just a Hook(线段树/成段更新)

    解题报告 题意: 原本区间1到n都是1,区间成段改变成一个值,求最后区间1到n的和. 思路: 线段树成段更新,区间去和. #include <iostream> #include < ...

  4. [HDU] 1698 Just a Hook [线段树区间替换]

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  5. 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 ...

  6. 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 ...

  7. HDU 1698 Just a Hook(线段树区间替换)

    题目地址:pid=1698">HDU 1698 区间替换裸题.相同利用lazy延迟标记数组,这里仅仅是当lazy下放的时候把以下的lazy也所有改成lazy就好了. 代码例如以下: # ...

  8. HDU 1698 Just a Hook(线段树 区间替换)

    Just a Hook [题目链接]Just a Hook [题目类型]线段树 区间替换 &题解: 线段树 区间替换 和区间求和 模板题 只不过不需要查询 题里只问了全部区间的和,所以seg[ ...

  9. (简单) HDU 1698 Just a Hook , 线段树+区间更新。

    Description: In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of ...

  10. 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 ...

随机推荐

  1. 能ping通网络,也正常连接,就是打不开网页,无法访问网络

    netsh winsock reset命令,作用是重置 Winsock 目录.如果一台机器上的Winsock协议配置有问题的话将会导致网络连接等问题,就需要用netsh winsock reset命令 ...

  2. day01--python基础1

    # 01讲   - Windows下执行程序,必须加 PYTHON.在LINUX下,可以不指明是PYTHON.但是,执行钱许给予hello.py执行权限. - 其次,只要变成可执行程序,必须第一行事前 ...

  3. install ironic-inspector

    安装相应的包和组件 yum install openstack-ironic-inspector python-ironic-inspector-client -y 创建user openstack ...

  4. python 由递归的dict构建树的画图代码

    createPlot(mytree)方法实现. 其中myTree是一个字典,调用retrieveTree(0)可以获得一个字典的样式. Last login: Thu Feb 23 19:07:53 ...

  5. Python编码报错

    Python默认编码错误SyntaxError: Non-ASCII character '\xe5'之解决方法在编写Python时,当使用中文输出或注释时运行脚本,会提示错误信息:SyntaxErr ...

  6. 架构师入门ing

    算法竞赛水平一般,算法工程师估计遥遥无期,准备开始架构方面的学习. 单纯依靠垂直提升硬件性能来提高系统性能的时代已结束,分布式开发的时代实际上早已悄悄地成为了时代的主流. 在一个团队里,架构师充当了技 ...

  7. CodeForces C. Maximal Intersection

    http://codeforces.com/contest/1029/problem/C You are given nn segments on a number line; each endpoi ...

  8. Android 开发中Service完全解析

    定义:服务,是Android四大组件之一,属于计算型组件 作用:提供 需在后台长期运行的服务 生命周期:          在Service的生命周期里,常用的有: (1) 4个手动调用的方法 手动调 ...

  9. [poj] 1149 PIGS || 最大流经典题目

    原题 题目大意 给你m个猪圈以及每个猪圈里原来有多少头猪,先后给你n个人,每个人能打开一些猪圈并且他们最多想买Ki头猪,在每一个人买完后能将打开的猪圈中的猪顺意分配在这次打开猪圈里,在下一个人来之前 ...

  10. 7月15号day7总结

    今天复习了springMVC的框架搭建. 思维导图: