[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 ...
随机推荐
- per-project basis
Of course, HSQLDB connection parameters should be stored on a per-project basis, instead of only onc ...
- (转) linux目录结构详细介绍
转自:http://yangrong.blog.51cto.com/6945369/1288072 目录 1.树状目录结构图 2./目录 3./etc/目录 4./usr/目录 5./var/目录 6 ...
- HDU3887 DFS序+ 线段树
查询树上某个节点的子节点的标号小于其标号的数目. 一个trick是建立线段树之后,从标号小的向标号大的来做更新. 1: #include <cstdio> 2: #include < ...
- js之正则表达式(上)
1.正则表达式的创建方式 两种方式创建:通过new修饰符创建和字面量的方式创建 1>new修饰符方式创建 var b2=new RegExp('Box','ig'); //第二个参数是 模式字符 ...
- LintCode-Word Segmentation
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separa ...
- c语言编程之队列(链表实现)
用链表实现了队列,完成了队列的入队和出队功能. #include"stdio.h" typedef int element; typedef struct Node{ struct ...
- Android 自定义Toast,不使用系统Toast
效果图: 创建Toast类 package com.example.messageboxtest; import android.app.Activity; import android.conten ...
- java集合类(六)About Queue
接上篇“java集合类(五)About Map” 终于来到了java集合类的尾声,太兴奋了,不是因为可以休息一阵了,而是因为又到了开启新知识的时刻,大家一起加油打气!!Come on...Fighti ...
- Timer定时器
try { mTimerGoOut = new Timer(); SimpleDateFormat sdf3 = new SimpleDateFormat("yyyy-MM-dd" ...
- java中的静态static关键字
类的静态成员函数不能访问非静态的成员函数以及非静态的成员变量, 但是反过来却是成立的. 即:非静态成员函数可以访问静态成员函数和静态成员变量. 这个可以从静态成员的特点来解释,因为静态成员属于类,因此 ...