#include <iostream>

#include <cstdio>

#include <string>

#include <cstring>

#include <fstream>

#include <algorithm>

#include <cmath>

#include <queue>

#include <stack>

#include <vector>

#include <map>

#include <set>

#include <iomanip>

using namespace std;

#define maxn 200005

#define MOD 1000000007

#define mem(a , b) memset(a , b , sizeof(a))

#define LL long long

#define ULL unsigned long long

const long long INF=0x3fffffff;

int n,m;

LL add[maxn<<2];

LL sum[maxn<<2];

void pushUp(int root)

{

sum[root]=sum[root<<1]+sum[root<<1|1];

}

void pushDown(int root,int m)

{

if(add[root]>0)

{

add[root<<1]=add[root];

add[root<<1|1]=add[root];

sum[root<<1]=(m-(m>>1))*add[root];

sum[root<<1|1]=(m>>1)*add[root];

add[root]=0;

}

}

void build(int l,int r,int root)

{

add[root]=0;

if(l==r)

{

sum[root]=1;

return ;

}

int mid=(l+r)>>1;

build(l,mid,root<<1);

build(mid+1,r,root<<1|1);

pushUp(root);

}

void updata(int rootL,int rootR,int v,int l,int r,int root)

{

if(rootL<=l&&rootR>=r)

{

add[root]=v;

sum[root]=add[root]*(r-l+1);

}

else

{

pushDown(root,r-l+1);

int mid=(r+l)>>1;

if(rootL<=mid)

updata(rootL, rootR, v, l, mid, root<<1);

if(rootR>mid)

updata(rootL, rootR, v, mid+1, r, root<<1|1);

pushUp(root);

}

}

int main()

{

int T;

int k=1;

scanf("%d",&T);

while(T--)

{

//mem(add,0);

scanf("%d",&n);

build(1,n,1);

scanf("%d",&m);

while(m--)

{

int rootL,rootR,v;

scanf("%d%d%d",&rootL,&rootR,&v);

updata(rootL, rootR, v, 1, n, 1);

}

printf("Case %d: The total value of the hook is ",k++);

printf("%lld.\n",sum[1]);

}

return 0;

}

线段树-区间更新-HDU 1689的更多相关文章

  1. 线段树 + 区间更新 ----- HDU 4902 : Nice boat

    Nice boat Time Limit: 30000/15000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tot ...

  2. HDU 5023 A Corrupt Mayor's Performance Art(线段树区间更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5023 解题报告:一面墙长度为n,有N个单元,每个单元编号从1到n,墙的初始的颜色是2,一共有30种颜色 ...

  3. HDU 4902 Nice boat 2014杭电多校训练赛第四场F题(线段树区间更新)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4902 解题报告:输入一个序列,然后有q次操作,操作有两种,第一种是把区间 (l,r) 变成x,第二种是 ...

  4. hdu 4031 attack 线段树区间更新

    Attack Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Subm ...

  5. hdu 3966(树链剖分+线段树区间更新)

    传送门:Problem 3966 https://www.cnblogs.com/violet-acmer/p/9711441.html 学习资料: [1]线段树区间更新:https://blog.c ...

  6. HDU.1556 Color the ball (线段树 区间更新 单点查询)

    HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...

  7. HDU 1556 Color the ball(线段树区间更新)

    Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...

  8. HDU 1698 线段树 区间更新求和

    一开始这条链子全都是1 #include<stdio.h> #include<string.h> #include<algorithm> #include<m ...

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

随机推荐

  1. xcode环境变量设置(转载)

    一般我们在xcode里面配置包含工程目录下头文件的时候,都要关联着相对路径和绝对路径,如果只是自己用这个项目,用绝对路径的问题不大,但是如果你把工程发给别人,别人就要在改这个绝对路径,这时候绝对路径的 ...

  2. 实用jQuery代码片段

    maco精选的一些jQuery代码,也许你从中可以举一反三[代码] [JavaScript]代码001<p>002    <h3><span >★ 使用jQuery ...

  3. BZOJ 1619 [Usaco2008 Nov]Guarding the Farm 保卫牧场:dfs【灌水】

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1619 题意: 给你一个n*m的地形图,位置(x,y)的海拔为h[x][y]. 一个山顶的定 ...

  4. FusionCharts Free 甘特图

    用FusionCharts做甘特图 1.同步方式(用xml格式字符) 前台aspx代码 <!DOCTYPE html> <html xmlns="http://www.w3 ...

  5. 用php描述顺序查找

    //顺序查找(数组里查找某个元素) $arr = array(3,55,45,2,67,76,6.7,-65,85,4); function seq_sch($array, $k){ for($i=0 ...

  6. [原创]java在线比较两个word文件

    一.项目背景 开发文档管理系统或OA办公系统的时候,实现在线处理word文档的功能比较容易,但是也经常会有客户提出文档版本管理的需求,这就需要同时在线打开两个word文件,对比两个不同版本的word文 ...

  7. bind (ERROR 502): bind(0.0.0.0:9501) failed. Error: Address already in use [98] (端口被占用)

    运行 swoole_server 服务报错显示端口被占用 解决思路: 1.用命令查看该端口 看是否存在 netstat  -anp  |  grep 9501 2.如果存在 就用 kill对应端口号 ...

  8. OJ提交题目中的语言选项里G++与C++的区别

    一.OJ提交题目中的语言选项里G++与C++的区别 http://www.th7.cn/Program/cp/201405/199001.shtml 首先更正一个概念,C++是一门计算机编程语言,G+ ...

  9. vue-cli创建项目 一直downloading解决办法

    vue-cli创建项目: 1 安装node(需要npm,npm是node的包管理股工具) 2 安装cnpm 3 安装vue-cli       cnpm install vue-cli -g 4 创建 ...

  10. window.open全屏

    window.open全屏   1. window.open(url,'资金计划项超支提醒','width='+(window.screen.availWidth-10)+',height='+(wi ...