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. DbVisualizer 解决中文乱码问题

    在SQL Commander中,sql语句中如果有中文,显示是‘口口口’. 解决办法如下: 在Tools->tool Properties->General->Appearance- ...

  2. Python zip()函数实现并行迭代

    示例1: for i, j in zip(range(0, 10), range(1, 11)): print(i, j) 输出结果: 0 11 22 33 44 55 66 77 88 99 10 ...

  3. SpringMVC 集成 Freemarker 模板引擎

    本文通过 maven 项目中集成 1.引入 SpringMVC 与 Freemarker 需要的依赖 <!-- SpringMVC --> <dependency> <g ...

  4. Python全栈工程师(每周总结:2)

     ParisGabriel   感谢 大家的支持                                                               每天坚持 一天一篇 点个订 ...

  5. svn 数据库 账号密码

    47.106.107.201 云商传媒李孔文 2018/8/22 19:26:35 root 云商传媒李孔文 2018/8/22 19:26:39 sn123456 云商传媒李孔文 2018/8/22 ...

  6. JavaWeb笔记(四)Cookie&Session

    Cookie 客户端会话技术,客户端保存,用于存储少量不太敏感的数据,在不登陆的情况下完成服务器对客户端的身份识别 简单使用步骤 创建Cookie对象,绑定数据 new Cookie(String n ...

  7. Access连接字符串

    Access2007没有密码连接: <connectionStrings> <add name="myconn" connectionString="P ...

  8. Oracle 数据库导出时 EXP-00008;ORA-00904

    问题是客户端和服务器端版本问题,我本地是11g,而服务器端是10g. 规则1:低版本的exp/imp可以连接到高版本(或同版本)的数据库服务器,但高版本的exp/imp不能连接到低版本的数据库服务器. ...

  9. 一个自动安装LNMP的简洁Shell脚本

    此脚本在生产服务器上使用了一年多,本脚本崇尚简单唯美,只需要一个脚本就可以在任何一台有网络的服务器上自动配置LNMP.本脚本会在脚本执行目录下,建packages目录用于存放LNMP所需要的软件.大家 ...

  10. ES6 学习体会

    第一部分: 1.初始化项目 npm init -y 2.安装ES6 环境 .babelrc 文件 babel-cli -g babel-ecmascript2015 babel-cli --save- ...