#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. Docker的远程访问

    $docker : info (10.211.55是另一台服务器的地址) 频繁访问远程的docker服务器使用-H选项很麻烦,使用环境变量DOCKER_HOST, $export DOCKER_HOS ...

  2. leetcode 750. Number Of Corner Rectangles

    Given a grid where each entry is only 0 or 1, find the number of corner rectangles. A corner rectang ...

  3. vuejs实现折叠面板展开收缩动画

    vuejs通过css3实现元素固定高度到auto高度的动画和auto高度到固定高度的动画. 循环列表,html: <template> <div class="newsli ...

  4. Retina屏幕下image-set

    实现Retina屏幕下图像的显示方法,还特别给我截取了一段代码: .soso .logo .qqlogo { display: block; width: 134px; height: 44px; b ...

  5. 6个基本screen命令

    screen -S  <name>    直接建立并进入<name>窗口 control+a    d    暂时退出窗口 (在会话内) screen -r <name& ...

  6. scroll或是其子类被添加进view时,界面自动上移

    开发中经常会遇到ViewController添加scroll或是其子类被添加进controller.view时,scroll会自动下移大概64像素 解决: self.edgesForExtendedL ...

  7. ffmpeg 中av_rescale_rnd 的含义

    http://blog.csdn.net/fireroll/article/details/8485482 一.函数声明: int64_t av_rescale_rnd(int64_t a, int6 ...

  8. python berkeley 操作——尤其提示 需版本匹配

    python berkeley 操作 先到http://www.oracle.com/technetwork/database/database-technologies/berkeleydb/dow ...

  9. codeforces 702B B. Powers of Two(水题)

    题目链接: B. Powers of Two time limit per test 3 seconds memory limit per test 256 megabytes input stand ...

  10. JAVA 内部类 (三)实例

    为什么要用内部类:控制框架 一个“应用程序框架”是指一个或一系列类,它们专门设计用来解决特定类型的问题.为应用应用程序框架,我们可从一个或多个类继承,并覆盖其中的部分方法.我们在覆盖方法中编写的代码用 ...