线段树-区间更新-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 ...
随机推荐
- Android Weekly Notes Issue #252
Android Weekly Issue #252 April 9th, 2017 Android Weekly Issue #252. 本期内容: 变化的渐变背景实现; Kotlin 1.1特性; ...
- ActivityManagerService服务线程启动源码分析【转】
本文转载自:http://blog.csdn.net/yangwen123/article/details/8177702 Android系统服务线程都驻留在SystemServer进程中,由Syst ...
- Java8初体验(2):Stream语法详解
原文出处: 一冰_天锦 上篇文章Java8初体验(1):lambda表达式语法比较详细的介绍了lambda表达式的方方面面,细心的读者会发现那篇文章的例子中有很多Stream的例子.这些Stream的 ...
- 记录下 hubot相关
适配器工厂https://hubot.github.com/docs/adapters/ 自己写适配器https://hubot.github.com/docs/adapters/developmen ...
- break和continue 都是指的最接近的内层循环
break和continue 都是指的最接近的内层循环
- Vue父子组件间的通信
父组件通过 props 向下传递数据给子组件,子组件通过 events 向上给父组件发送消息. 父组件: <div> <div style="background:#344 ...
- SQL.py
import sqlite3,sys def convert(value): if value.startswith('~'): return value.strip('~') if not valu ...
- Notice:Array to string conversion的问题
如果后台或者前端输出这样的提示: Notice: Array to string conversion 原因是:用 echo 来输出数组,当然会报错,数组应该用print , print_r , 或 ...
- 【原】RHEL6.0企业版安装
作者:david_zhang@sh [转载时请以超链接形式标明文章] 链接:http://www.cnblogs.com/david-zhang-index/p/4166846.html 本文适用RH ...
- Qt-MVC图形视图框架初识
使用QPushButton.QLabel.QCheckBox等构成GUI的控件或自定义图形时,开发应用程序会变得很简单.但是如果想在GUI中使用数十个或者数百个图形对象,向用户完美展示控制场景,则会受 ...