hdu 1698 线段树(成段替换 区间求和)

时间:2022-08-29 07:41:09

一条钩子由许多小钩子组成 更新一段小钩子 变成铜银金 价值分别变成1 2 3 输出最后的总价值

Sample Input
1
10
2
1 5 2
5 9 3

Sample Output
Case 1: The total value of the hook is 24.

 # include <iostream>
# include <cstdio>
# include <cstring>
# include <algorithm>
# include <cmath>
# include <queue>
# define LL long long
using namespace std ; const int maxn = ; int sum[maxn<<] ; //结点开4倍
int col[maxn<<] ; //延迟标记 void PushUP(int rt) //更新到父节点
{
sum[rt] = sum[rt * ] + sum[rt * + ] ; //rt 为当前结点
} void PushDown(int rt , int m ) //向下更新
{
if (col[rt])
{
col[rt * ] = col[rt * + ] = col[rt] ;
sum[rt * ] = (m - m / ) * col[rt] ;
sum[rt * + ] = (m / ) * 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(l , m , rt * ) ;
build(m + , r , rt * +) ;
PushUP(rt) ;
} void updata(int L , int R , int c , int l , int r , int rt)
{
if (L <= l && r <= R)
{
col[rt] = c ;
sum[rt] = (r - l + ) * c ;
return ;
}
PushDown(rt , r - l + ) ;
int m = (l + r) / ; if (L <= m)
updata(L , R , c , l , m , rt * ) ;
if (R > m)
updata(L , R , c , m + , r , rt * + ) ; PushUP(rt) ;
} int main ()
{
//freopen("in.txt","r",stdin) ;
int n , m ;
int T ;
int Case = ;
scanf("%d" , &T) ;
while(T--)
{
Case++ ;
scanf("%d%d",&n,&m);
build( , n , ) ;
while(m--)
{
int a , b , c ;
scanf("%d%d%d",&a,&b,&c);
updata(a , b , c , , n , ) ;
}
printf("Case %d: The total value of the hook is %d.\n",Case , sum[]);
} return ;
}

hdu 1698 线段树(成段替换 区间求和)的更多相关文章

  1. POJ 3468 A Simple Problem with Integers&lpar;线段树 成段增减&plus;区间求和&rpar;

    A Simple Problem with Integers [题目链接]A Simple Problem with Integers [题目类型]线段树 成段增减+区间求和 &题解: 线段树 ...

  2. poj 3468 线段树 成段增减 区间求和

    题意:Q是询问区间和,C是在区间内每个节点加上一个值 Sample Input 10 51 2 3 4 5 6 7 8 9 10Q 4 4Q 1 10Q 2 4C 3 6 3Q 2 4Sample O ...

  3. hdu 1698 线段树成段更新

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698 #include <cstdio> #include <cmath> # ...

  4. hdu 1698 线段树 成段更新

    题意:一段钩子,每个钩子的值为1,有若干更新,每次跟新某段的值,若干查询某段的和 基础题了 #include<cstdio> #include<iostream> #inclu ...

  5. HDU 3577 Fast Arrangement &lpar; 线段树 成段更新 区间最值 区间最大覆盖次数 &rpar;

    线段树成段更新+区间最值. 注意某人的乘车区间是[a, b-1],因为他在b站就下车了. #include <cstdio> #include <cstring> #inclu ...

  6. hdu 1754 线段树(单点替换 区间最值)

    Sample Input5 61 2 3 4 5Q 1 5 //1-5结点的最大值U 3 6 //将点3的数值换成6Q 3 4Q 4 5U 2 9Q 1 5 Sample Output5659 # i ...

  7. POJ训练计划2777&lowbar;Count Color&lpar;线段树&sol;成段更新&sol;区间染色&rpar;

    解题报告 题意: 对线段染色.询问线段区间的颜色种数. 思路: 本来直接在线段树上染色,lz标记颜色.每次查询的话訪问线段树,求出颜色种数.结果超时了,最坏的情况下,染色能够染到叶子节点. 换成存下区 ...

  8. HDU 4893 线段树的 点更新 区间求和

    Wow! Such Sequence! Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  9. hdu 1166 线段树(单点增减 区间求和)

    Sample Input1101 2 3 4 5 6 7 8 9 10Query 1 3Add 3 6Query 2 7Sub 10 2Add 6 3Query 3 10End Sample Outp ...

随机推荐

  1. TEA&lpar;Tiny Encryption Algorithm&rpar;

    简介 TEA是一种简单高效的加解密算法,以速度快,实现简单著称.TEA算法每一次可以操作64-bit数据,采用128-bit作为key,算法采用迭代的形式,推荐的迭代轮数是64,最少32. 代码(默认 ...

  2. Kik CEO Ted Livingston发博称要成为西方的微信&quest;

    加拿大手机聊天应用Kik是一款手机通信录的社交软件,和Snapchat.微信相似,上个月刚拿到3830万美元融资.近日,Kik CEO Ted Livingston在medium博客上发表了the r ...

  3. WCF中Service Configuration Editor的使用方法

    1.在App.config文件上右击,选择Edit WCF Configuration.... 或者打开Program Files\Microsoft Visual Studio 8\Common7\ ...

  4. 【h5-egret】如何快速开发一个小游戏

    1.环境搭建 安装教程传送门:http://edn.egret.com/cn/index.php?g=&m=article&a=index&id=207&terms1_ ...

  5. 一个操作Sql2005数据库的类(备份,还原,分离,附加,添加删除用户等操作)&lpar;转载&rpar;

    /* * 更新时间 :2011-09-01 16:06 * 更 新 人 :苏飞 */ using System; using System.Collections.Generic; using Sys ...

  6. 【ASP&period;NET Core快速入门】(十)Cookie-based认证实现

    准备工作 新建MVC项目,然后用VSCode打开 dotnet new mvc --name MvcCookieAuthSample 在Controllers文件夹下新建AdminController ...

  7. JGit 切换分支

    //gitDir是git仓库的根目录,这个仓库必须是已clone好了 File file = new File(gitDir); Git git = Git.open(file); //切换分支, i ...

  8. &lbrack;宏&rsqb;preempt&lowbar;disable

    //include/linux/preempt.h #ifdef CONFIG_PREEMPT_COUNT //如果内核支持抢占 do { \ inc_preempt_count(); \ barri ...

  9. achartengine(Google给android提供的画图工具包)的介绍和使用

    AChartEngine(ACE)是Google为Android提供的一个开源绘制工具包.它集成了绘制多种图形的功能:折线图.散点图.气泡图.柱状图.饼图.仪表图等图形. 下载地址:http://do ...

  10. 【前端】直击源头的让你3秒理解并且会用Jsonp!!!

    1. 同源策略 ajax之所以需要“跨域”,罪魁祸首就是浏览器的同源策略.即,一个页面的ajax只能获取这个页面相同源或者相同域的数据. 如何叫“同源”或者“同域”呢?——协议.域名.端口号都必须相同 ...