[HDOJ1698]Just a Hook(线段树,区间更新)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698
陈题,更新后查询所有叶节点的和。撸一遍模版,形成自己的风格。
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath> using namespace std; #define fr first
#define sc second
#define pb(a) push_back(a)
#define Rint(a) scanf("%d", &a)
#define Rll(a) scanf("%I64d", &a)
#define Rs(a) scanf("%s", a)
#define FRead() freopen("in", "r", stdin)
#define FWrite() freopen("out", "w", stdout)
#define Rep(i, len) for(int i = 0; i < (len); i++)
#define For(i, a, len) for(int i = (a); i < (len); i++)
#define Cls(a) memset((a), 0, sizeof(a))
#define Full(a) memset((a), 0x7f7f, sizeof(a)) typedef struct Node {
int lo, hi;
Node() {}
Node(int l, int h) : lo(l), hi(h) {}
}Node; #define lrt rt << 1
#define rrt rt << 1 | 1
const int maxn = ;
int sum[maxn<<];
int add[maxn<<];
int n, q; void pushUP(int rt) {
sum[rt] = sum[lrt] + sum[rrt];
} void pushDOWN(int rt, int m) {
if(add[rt]) {
add[lrt] = add[rrt] = add[rt];
sum[lrt] = (m - (m >> )) * add[rrt];
sum[rrt] = (m >> ) * add[lrt];
add[rt] = ;
}
} void build(int l, int r, int rt) {
add[rt] = ;
sum[rt] = ;
if(l == r) return;
int m = (l + r) >> ;
build(l, m, lrt);
build(m+, r, rrt);
pushUP(rt);
} void update(int L, int R, int c, int l, int r, int rt) {
if(l >= L && R >= r) {
add[rt] = c;
sum[rt] = int(c * (r - l + ));
return;
}
pushDOWN(rt, r-l+);
int m = (l + r) >> ;
int ret = ;
if(m >= L) update(L, R, c, l, m, lrt);
if(m < R) update(L, R, c, m+, r, rrt);
pushUP(rt);
} int main() {
// FRead();
int T, _ = ;
int x, y, z;
Rint(T);
while(T--) {
Rint(n); Rint(q);
build(, n, );
Rep(i, q) {
Rint(x); Rint(y); Rint(z);
update(x, y, z, , n, );
}
printf("Case %d: The total value of the hook is %d.\n", _++, sum[]);
}
return ;
}
[HDOJ1698]Just a Hook(线段树,区间更新)的更多相关文章
- (简单) HDU 1698 Just a Hook , 线段树+区间更新。
Description: In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of ...
- HDU 1698 Just a Hook(线段树区间更新查询)
描述 In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of the heroes ...
- Just a Hook 线段树 区间更新
Just a Hook In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of t ...
- 【原创】hdu1698 Just a Hook(线段树→区间更新,区间查询)
学习线段树第二天,这道题属于第二简单的线段树,第一简单是单点更新,这个属于区间更新. 区间更新就是lazy思想,我来按照自己浅薄的理解谈谈lazy思想: 就是在数据结构中,树形结构可以线性存储(线性表 ...
- hdu - 1689 Just a Hook (线段树区间更新)
http://acm.hdu.edu.cn/showproblem.php?pid=1698 n个数初始每个数的价值为1,接下来有m个更新,每次x,y,z 把x,y区间的数的价值更新为z(1<= ...
- hdu1698 Just a hook 线段树区间更新
题解: 和hdu1166敌兵布阵不同的是 这道题需要区间更新(成段更新). 单点更新不用说了比较简单,区间更新的话,如果每次都更新到底的话,有点费时间. 这里就体现了线段树的另一个重要思想:延迟标记. ...
- HDU1698:Just a Hook(线段树区间更新)
Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing for m ...
- HDU 1698 Just a Hook 线段树区间更新、
来谈谈自己对延迟标记(lazy标记)的理解吧. lazy标记的主要作用是尽可能的降低时间复杂度. 这样说吧. 如果你不用lazy标记,那么你对于一个区间更新的话是要对其所有的子区间都更新一次,但如果用 ...
- hdu1698 Just a Hook (线段树区间更新 懒惰标记)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- hdu-------(1698)Just a Hook(线段树区间更新)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
随机推荐
- MVC的小知识点
1.MVC的前台页面编译完之后,也会生成一个前台页面类.在前天页面中加入这段代码this.GetType().Assembly.GetLocation()得到当前类所在的程序集,可以查看其所在的程序, ...
- Extjs ajax form 提交
1.form 提交 form.form.submit({ url: "/HandlerExcelToDB/UploadFile.ashx", params: {}, success ...
- DB天气app冲刺二阶段第四天
今天就进度来说没有丝毫进度..考虑直接把数据库文件弄到代码里.因为每次挑选城市的时候都有时会出bug ,所以我想明天试一下看看是不是这个的问题,虽然工程量有点大,但是应该不困难,所以明天试一下需要. ...
- iOS VideoToolbox硬编H.265(HEVC)H.264(AVC):1 概述
本文档尝试用Video Toolbox进行H.265(HEVC)硬件编码,视频源为iPhone后置摄像头.去年做完硬解H.264,没做编码,技能上感觉有些缺失.正好刚才发现CMFormatDescri ...
- pure.css
注释中address是纠正的意思 等价于correct/*! Pure v0.5.0 Copyright 2014 Yahoo! Inc. All rights reserved. Licensed ...
- ./configure --prefix=
一直用这个选项prefix=,但不知道,啥意思. 转载自:----------------------------------------------------------------------- ...
- 【BZOJ】【2132】圈地计划
网络流/最小割 Orz Hzwer 这类大概是最小割建模中的经典应用吧…… 黑白染色,然后反转黑色的技巧感觉很巧妙!这个转化太神奇了…… /****************************** ...
- 【POJ】【3164】Commond Network
最小树形图 最小树形图模板题,朱-刘算法. 题解:http://blog.csdn.net/shuangde800/article/details/8039359 这位大神代码写的非常通俗易懂,而且这 ...
- oracle 条件:1=1或1=0,动态添加条件
看到where语句中有条件:where 1=1 和 1=2或1<>1 用途: 1=1:是为了添加条件时使用and并列其他条件时使用的(动态连接后续条件) 比如: ...
- PHP对XML文件操作类讲解
<?phpclass XML{ private $dom; function __construct () { $this->dom = new D ...