题目链接: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(线段树,区间更新)的更多相关文章

  1. (简单) HDU 1698 Just a Hook , 线段树+区间更新。

    Description: In the game of DotA, Pudge’s meat hook is actually the most horrible thing for most of ...

  2. 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 ...

  3. 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 ...

  4. 【原创】hdu1698 Just a Hook(线段树→区间更新,区间查询)

    学习线段树第二天,这道题属于第二简单的线段树,第一简单是单点更新,这个属于区间更新. 区间更新就是lazy思想,我来按照自己浅薄的理解谈谈lazy思想: 就是在数据结构中,树形结构可以线性存储(线性表 ...

  5. hdu - 1689 Just a Hook (线段树区间更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=1698 n个数初始每个数的价值为1,接下来有m个更新,每次x,y,z 把x,y区间的数的价值更新为z(1<= ...

  6. hdu1698 Just a hook 线段树区间更新

    题解: 和hdu1166敌兵布阵不同的是 这道题需要区间更新(成段更新). 单点更新不用说了比较简单,区间更新的话,如果每次都更新到底的话,有点费时间. 这里就体现了线段树的另一个重要思想:延迟标记. ...

  7. HDU1698:Just a Hook(线段树区间更新)

    Problem Description In the game of DotA, Pudge’s meat hook is actually the most horrible thing for m ...

  8. HDU 1698 Just a Hook 线段树区间更新、

    来谈谈自己对延迟标记(lazy标记)的理解吧. lazy标记的主要作用是尽可能的降低时间复杂度. 这样说吧. 如果你不用lazy标记,那么你对于一个区间更新的话是要对其所有的子区间都更新一次,但如果用 ...

  9. hdu1698 Just a Hook (线段树区间更新 懒惰标记)

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  10. hdu-------(1698)Just a Hook(线段树区间更新)

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

随机推荐

  1. iOS常见问题(1)

    一.storyboard连线问题 产生原因:将与storyboard关联的属性删除了,但是storyboard中还保持之前所关联的属性. 解决: 1.点击view controller 2.点击这排最 ...

  2. C++中使用心得

    1.struct成员默认访问方式是public,而 class默认访问方式是private! 2.exit函数终止程序执行会调用析构函数 ,abort函数终止程序不会调用析构函数! 3.静态局部变量直 ...

  3. sky A800s手机恢复出厂设置操作

    关机的情况下,手指一起按这3个按键(音量下键+搜索键+开机键)看到SKY标志后即可松手,就可以进入恢复界面恢复界面操作方法:音量上下键为上下移动,关机键为选择.选择 wipe data/factory ...

  4. oracle 常用SQL语法手册

    Select 用途: 从指定表中取出指定的列的数据 语法: SELECT column_name(s) FROM table_name 解释: 从数据库中选取资料列,并允许从一或多个资料表中,选取一或 ...

  5. .Net webservice动态调用

    直接贴代码吧 public class PmsService { /// <summary> /// pms接口 /// </summary> /// <param na ...

  6. Careercup - Facebook面试题 - 5188884744896512

    2014-05-02 07:18 题目链接 原题: boolean isBST(const Node* node) { // return true iff the tree with root 'n ...

  7. asp.net中的mysql传参数MySqlParameter

    注意在asp.net中传参 string sql="select name,id from user where id=@id"; //@idm不需要引号 MySqlParamet ...

  8. JUnit4的使用

    JUnit4是JUnit框架有史以来的最大改进,其主要目标便是利用Java5的Annotation特性简化测试用例的编写. 先简单解释一下什么是Annotation,这个单词一般是翻译成元数据.元数据 ...

  9. Oracle 一次执行多条语句

    在.Net使用多次方法一次执行多条语句都不成功, 百度了许久才找到正确的解决方案. Oracle执行多条语句的时候 不能有物理换行 写法对比: 如下写法是不成功. begin into t_test ...

  10. Memcache安全配置

    Memcache安全配置 瞌睡龙 · 2014/01/20 17:59 0x00 Memcache简介 Memcache是一个高性能的分布式的内存对象缓存系统,通过在内存里维护一个统一的巨大的hash ...