#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. [haoi2008]玩具命名

    某人有一套玩具,并想法给玩具命名.首先他选择WING四个字母中的任意一个字母作为玩具的基本名字.然后他会根据自己的喜好,将名字中任意一个字母用“WING”中任意两个字母代替,使得自己的名字能够扩充得很 ...

  2. java random配置修改

    不知道 报啥错的时候 ,改这个 vim /usr/java/latest/jre/lib/security/java.security 原值: securerandom.source=file:/de ...

  3. CentOS中文乱码之解决办法

    在学习Linux的过程中,最先碰到的是通过SSH终端连接时发现有乱码出现,使用这篇文章先从这里说起. 在 ssh , telnet 终端中文显示乱码解决办法#vim /etc/sysconfig/i1 ...

  4. win7下使用source insight,没有Courier字体

    http://hi.baidu.com/raoxj/item/0e3a3a3b2461c5be134b14fa 1. “控制面板:--->“字体”--->找到Courier New(建议用 ...

  5. 用mingw-w64 编译 x64 位的ffmpeg

    http://blog.sina.com.cn/s/blog_6125d067010168dt.html 工作中用到了ffmpeg x64. 发现编译出来x64的ffmpeg,很不容易.特记录下来.原 ...

  6. servlet串行拦截器实现例子

    至于串行过滤器有什么作用,我实在不知.我的理解是它只是说明 过滤器的串行运行方式 需求:当用户没有登录访问更新页面的时候,跳转到登录页面 1.登录页面:login.jsp <%@ page la ...

  7. ora-12519:TNS ,no appropriate service handler found

    今天有同事反应,数据库连不了,提示 ora-12519:TNS ,no appropriate service handler found: 一开始以为监听没有启动,排查后,发现正常:于是google ...

  8. C++ 两款静态检查工具

    pclint(收费) http://www.gimpel.com/html/pcl.htmpc-lint是资格最老,最强力的代码检查工具,但是是收费软件,并且配置起来有一点点麻烦. ccpchecke ...

  9. git搭建私有仓库

    git gui参考 https://ask.helplib.com/git/post_1004941

  10. 技术胖Flutter第三季-18布局CardWidget 卡片布局组件

    技术胖Flutter第三季-18布局CardWidget 卡片布局组件 博客地址: https://jspang.com/post/flutter3.html#toc-420 最外面是Card布局,里 ...