#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. CentOS-7-64bit 下为firefox安装flashplayer

    最近更新了Centos 7 还是有一些不习惯的 给ff安flashplayer插件时,按centos 6.x的方法时都无法成功,后来find了一下,才知道firefox还有一个64bit的文件夹: 解 ...

  2. spring boot 整合 quartz 集群环境 实现 动态定时任务配置【原】

    最近做了一个spring boot 整合 quartz  实现 动态定时任务配置,在集群环境下运行的 任务.能够对定时任务,动态的进行增删改查,界面效果图如下: 1. 在项目中引入jar 2. 将需要 ...

  3. java基础以及操作Excle

    今天把会经常用的几个集合的迭代方法又练习了一下,放在这里,经常复习! map集合迭代 /*** 迭代map[1]*/ for (Integer key : map.keySet()) {//迭代key ...

  4. Codeforces Round #373 (Div. 2) Anatoly and Cockroaches —— 贪心

    题目链接:http://codeforces.com/contest/719/problem/B B. Anatoly and Cockroaches time limit per test 1 se ...

  5. Codeforces Round #371 (Div. 2) C. Sonya and Queries —— 二进制压缩

    题目链接:http://codeforces.com/contest/714/problem/C C. Sonya and Queries time limit per test 1 second m ...

  6. hadoop 常用命令总结

    1. 查看集群资源信息 hdfs dfsadmin -report 2. 启动一个mapreduce任务, hadoop jar /opt/hadoop/share/hadoop/tools/lib/ ...

  7. wpf图片定点缩放

    去年犯小人,万事不顺,4月刚换工作,开始新工作 遇到一个小问题,需要读取图片,然后对图片进行定点缩放,很简答的逻辑,很简单的代码,但是,这尼玛我被wpf给坑了,这一坑就是三天 好了,很简单的一个UI ...

  8. __FILE__,__LINE__,__func__ 真好用,DEBUG利器啊!

    我是不喜欢用类似VC下的F5,F10.曾经很喜欢用.被代码逻辑逼的没招了.所以不喜欢用了. 比如,错误是根据动态数据,产生的行为错误,无论是该写的未写,还是不该写的写了.指针跑飞什么等等,无非就是上述 ...

  9. 小程序rpx

    rpx是微信小程序解决自适应屏幕尺寸的尺寸单位.微信小程序规定屏幕的宽度是750rpx, 微信小程序也支持rem尺寸单位,rem规定屏幕的宽度是20rem vw vh适配 vw和vh是css3中的新单 ...

  10. 机器学习之逻辑回归(logistic回归)

    前言            以下内容是个人学习之后的感悟,转载请注明出处~ 逻辑回归 一.为什么使用logistic回归   一般来说,回归不用在分类问题上,因为回归是连续型模型,而且受噪声影响比较大 ...