[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 ...
随机推荐
- Google history
传说,硅谷的公司在和微软的竞争中一直处于下风,不论在市场,人才,还是在打官司上,直到婴儿巨人Baby Giant谷歌的出现,历史才出现前所未有的改变.Google以一个强大的挑战者的身份出现在人们的视 ...
- [resource]Python机器学习库
reference: http://qxde01.blog.163.com/blog/static/67335744201368101922991/ Python在科学计算领域,有两个重要的扩展模块: ...
- HDU 2821 Pusher
原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=2821 首先,题目描述给的链接游戏很好玩,建议先玩几关,后面越玩越难,我索性把这道题A了,也就相当于通关 ...
- 在线最优化求解(Online Optimization)之三:FOBOS
在线最优化求解(Online Optimization)之三:FOBOS FOBOS (Forward-Backward Splitting)是由John Duchi和Yoram Singer提出的[ ...
- State of Hyperparameter Selection
State of Hyperparameter Selection DANIEL SALTIEL VIEW NOTEBOOK Historically hyperparameter determina ...
- VS2010字体设置+推荐字体
字体的设置在工具->选项->环境->字体和颜色. 相信大家在用VS2010的时候都会觉得默认的字体不是很好看,尤其是看的时间长了以后,更是累眼睛,这里推荐一个字体,个人感觉像是加粗加 ...
- hadoop浅尝 hadoop与hbase交互
在安装好hbase之后,运行一个与hadoop无关的纯hbase程序成功了. 接着写一个hadoop与hbase进行交互的小程序,这个程序的运行方法依然与前文相同, 即导出jar文件在shell下运行 ...
- JsRender系列demo(4)-if else
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- CentOS中基于不同版本安装重复包的解决方案
http://blog.chinaunix.net/uid-21710705-id-3039675.html
- hdu 1288 Hat's Tea
这个要慢慢理解…… ;}