线段树-区间更新-HDU 1689
#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的更多相关文章
- 线段树 + 区间更新 ----- HDU 4902 : Nice boat
Nice boat Time Limit: 30000/15000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Tot ...
- HDU 5023 A Corrupt Mayor's Performance Art(线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5023 解题报告:一面墙长度为n,有N个单元,每个单元编号从1到n,墙的初始的颜色是2,一共有30种颜色 ...
- HDU 4902 Nice boat 2014杭电多校训练赛第四场F题(线段树区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4902 解题报告:输入一个序列,然后有q次操作,操作有两种,第一种是把区间 (l,r) 变成x,第二种是 ...
- hdu 4031 attack 线段树区间更新
Attack Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others)Total Subm ...
- hdu 3966(树链剖分+线段树区间更新)
传送门:Problem 3966 https://www.cnblogs.com/violet-acmer/p/9711441.html 学习资料: [1]线段树区间更新:https://blog.c ...
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- HDU 1556 Color the ball(线段树区间更新)
Color the ball 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...
- HDU 1698 线段树 区间更新求和
一开始这条链子全都是1 #include<stdio.h> #include<string.h> #include<algorithm> #include<m ...
- (简单) HDU 1698 Just a Hook , 线段树+区间更新。
Description: In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of ...
随机推荐
- POJ 2506 Tiling (递推 + 大数加法模拟 )
Tiling Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7965 Accepted: 3866 Descriptio ...
- the art of seo(chapter six)
Developing an SEO-Friendly Website ***Making Your Site Accessible to Search Engines***1.Indexable Co ...
- deepin软件中文乱码
如图所示,deepin软件,会有这种情况,中文全是乱码,口口口.这表示很讨厌,学长给出的解决办法,将系统换成英文语言,这样确实解决了乱码,但是还是有问题,比如在写中文注释,又变成这样了. 去deepi ...
- hdu-2647 Reward && hdu-2049产生冠军 &&hdu-3342Legal or Not(拓扑排序)
题目链接: hdu-2647 /*Problem : 2647 ( Reward ) Judge Status : Accepted RunId : 16919085 Language : G++ A ...
- Pyhton:汉诺塔游戏
#汉诺塔游戏攻略! def hanoi(n,x,y,z): if n == 1: print(x,'-->',z) else: hanoi(n-1,x,z,y) #将前n-1个盘子从x移动到y上 ...
- 51nod-1065:最小正子段和(STL)
N个整数组成的序列a11,a22,a33,…,ann,从中选出一个子序列(aii,ai+1i+1,…ajj),使这个子序列的和>0,并且这个和是所有和>0的子序列中最小的. 例如:4,-1 ...
- mtk6737t摄像头配置文件的编译
修改摄像头的配置文件后,一直没有编译生效,要make一遍才生效,最终查出编译配置的方法摄像头配置文件路径 vendor/mediatek/proprietary/custom/mt6735/hal/D ...
- hibernate 中的拦截器EmptyInterceptor接口功能
Interceptor接口提供了从会话(session)回调(callback)应用程序(application)的机制, 这种回调机制可以允许应用程序在持久化对象被保存.更新.删除或是加载之前,检查 ...
- 获取当前正在运行的activity
adb shell dumpsys activity activities | findstr "Run"
- live555 基本类之间的关系
live555 中存在这5个最基本的类.每个类中都拥有一个BasicUsageEnvironment. 这是这几个类之间的相互关系. MediaSession可以拥有多个subsession.