HDU 1698 Just a Hook(线段树区间替换)
题目地址: pid=1698">HDU 1698
区间替换裸题。相同利用lazy延迟标记数组,这里仅仅是当lazy下放的时候把以下的lazy也所有改成lazy就好了。
代码例如以下:
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm> using namespace std;
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1
const int MAXN=1e5+10;
int sum[MAXN<<3], lazy[MAXN<<3];
void PushUp(int rt)
{
sum[rt]=sum[rt<<1]+sum[rt<<1|1];
}
void PushDown(int rt, int m)
{
if(lazy[rt])
{
lazy[rt<<1]=lazy[rt<<1|1]=lazy[rt];
sum[rt<<1]=lazy[rt]*(m-(m>>1));
sum[rt<<1|1]=lazy[rt]*(m>>1);
lazy[rt]=0;
}
}
void build(int l, int r, int rt)
{
lazy[rt]=0;
if(l==r)
{
sum[rt]=1;
return ;
}
int mid=l+r>>1;
build(lson);
build(rson);
PushUp(rt);
}
void update(int ll, int rr, int x, int l, int r, int rt)
{
if(ll<=l&&rr>=r)
{
lazy[rt]=x;
sum[rt]=(r-l+1)*x;
return ;
}
PushDown(rt, r-l+1);
int mid=l+r>>1;
if(ll<=mid) update(ll,rr,x,lson);
if(rr>mid) update(ll,rr,x,rson);
PushUp(rt);
}
int main()
{
int n, i, a, b, c, t, q, num=0;
scanf("%d",&t);
while(t--)
{
num++;
scanf("%d",&n);
build(1,n,1);
scanf("%d",&q);
while(q--)
{
scanf("%d%d%d",&a,&b,&c);
update(a,b,c,1,n,1);
}
printf("Case %d: The total value of the hook is %d.\n",num,sum[1]);
}
return 0;
}
HDU 1698 Just a Hook(线段树区间替换)的更多相关文章
- HDU 1698 Just a Hook(线段树 区间替换)
Just a Hook [题目链接]Just a Hook [题目类型]线段树 区间替换 &题解: 线段树 区间替换 和区间求和 模板题 只不过不需要查询 题里只问了全部区间的和,所以seg[ ...
- [HDU] 1698 Just a Hook [线段树区间替换]
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU.1689 Just a Hook (线段树 区间替换 区间总和)
HDU.1689 Just a Hook (线段树 区间替换 区间总和) 题意分析 一开始叶子节点均为1,操作为将[L,R]区间全部替换成C,求总区间[1,N]和 线段树维护区间和 . 建树的时候初始 ...
- (简单) 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 ...
- HDU 1698 Just a Hook 线段树区间更新、
来谈谈自己对延迟标记(lazy标记)的理解吧. lazy标记的主要作用是尽可能的降低时间复杂度. 这样说吧. 如果你不用lazy标记,那么你对于一个区间更新的话是要对其所有的子区间都更新一次,但如果用 ...
- HDU 1698 just a hook 线段树,区间定值,求和
Just a Hook Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1 ...
- HDU 1698 Just a Hook 线段树+lazy-target 区间刷新
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- hdu - 1689 Just a Hook (线段树区间更新)
http://acm.hdu.edu.cn/showproblem.php?pid=1698 n个数初始每个数的价值为1,接下来有m个更新,每次x,y,z 把x,y区间的数的价值更新为z(1<= ...
随机推荐
- LiveScript 函数
The LiveScript Book The LiveScript Book 函数 定义函数是非常轻量级的. 1.(x, y) -> x + y2.3.-> # an empty ...
- Codevs 1501 二叉树的最大宽度和高度
1501 二叉树最大宽度和高度 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 白银 Silver 题目描述 Description 给出一个二叉树,输出它的最大宽度和高度. 输入描 ...
- C#连接数据库SQL(2005)
原文发布时间为:2008-07-24 -- 来源于本人的百度文章 [由搬家工具导入] 总算把这起步的路走了.首先来总结一下进行数据库编程的全过程,这里用的是SQL SERVER(1)建立SqlConn ...
- 转 使用putty从linux主机上面往windows主机下面拷贝文件
更新一下,把putty的包解压以后,想要在dos窗口中直接使用,必须把putty解压的文件的路径添加到环境变量中,这样使用起来就会非常简单了. 郁闷了好久,终于搞定了putty的上传下载文件命令psc ...
- 47深入理解C指针之---指针与硬件
一.size_t:用于安全表示长度,所有平台和系统都会解析成自己对应的长度 1.定义:size_t类型表示C中任何对象所能表示的最大长度,是个无符号整数:常常定义在stdio.h或stdlib.h中 ...
- php自动获取字符串编码函数mb_detect_encoding
当在php中使用mb_detect_encoding函数进行编码识别时,很多人都碰到过识别编码有误的问题,例如对与GB2312和UTF- 8,或者UTF-8和GBK(这里主要是对于cp936的判断), ...
- mysql tinyint bit
Java bit 对应 mysql tinyint(1) false = 0 ,true = 1.
- LeetCode OJ——Convert Sorted Array to Binary Search Tree
http://oj.leetcode.com/problems/convert-sorted-array-to-binary-search-tree/ 将一个升序的数组转换成 height balan ...
- Unsafe in Java
http://www.cnblogs.com/xrq730/p/4976007.html http://www.importnew.com/14511.html http://blog.csdn.ne ...
- es6 --数组--Array.from() 、Array.isArray()、Array.of()、find()、findIndex()、fill()、entries() 、keys() ,values()
将两类对象转为真正的数组 Array.from()方法用于将两类对象转为真正的数组:类似数组的对象(array-like object)和可遍历(iterable)的对象(包括ES6新增的数据结构Se ...