题目地址:

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(线段树区间替换)的更多相关文章

  1. HDU 1698 Just a Hook(线段树 区间替换)

    Just a Hook [题目链接]Just a Hook [题目类型]线段树 区间替换 &题解: 线段树 区间替换 和区间求和 模板题 只不过不需要查询 题里只问了全部区间的和,所以seg[ ...

  2. [HDU] 1698 Just a Hook [线段树区间替换]

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

  3. HDU.1689 Just a Hook (线段树 区间替换 区间总和)

    HDU.1689 Just a Hook (线段树 区间替换 区间总和) 题意分析 一开始叶子节点均为1,操作为将[L,R]区间全部替换成C,求总区间[1,N]和 线段树维护区间和 . 建树的时候初始 ...

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

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

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

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

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

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

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

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

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

随机推荐

  1. Educational Codeforces Round 36 (Rated for Div. 2)

    A. Garden time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...

  2. 设计模式(十六)迭代器模式 Iterator

    什么时候需要用到迭代器模式? 有许多中方法,可以把对象堆起来放进一个集合(可以是数组.堆栈.列表.哈希表,等等). 每一种类型的集合,都有各自适用的时机.但是某个时间段,客户端可能希望去遍历这个集合. ...

  3. 性能学习之六---socket接口测试

    socket协议较底层,所以是一个万能协议.socket发的是数据包,所以较难看懂. 下面我们来讲解socket接口测试. 大致思路为:新建sever端和client端---建立连接---发送数据 一 ...

  4. [OJ#63]树句节够提

    [OJ#63]树句节够提 试题描述 给定一棵节点数为 N 的有根树,其中 1 号点是根节点,除此之外第 i 个节点的父亲为 fi.每个节点有一个权值 Ai,所有边权均为 1. 给定 Q 个询问,每个询 ...

  5. Java连接SQLite数据库

    下载java包:sqlite-jdbc-3.7.2.jar,放到java工程目录lib下 如下代码实例: import java.sql.*; import org.sqlite.JDBC; /** ...

  6. ServletContext ActionContext ServletActionContext

    1> ServletContext--------->SessionContext>RequestContext>PageContext 一个 WEB 运用程序只有一个 Ser ...

  7. APUE 学习笔记(三) 文件和目录

    1. 文件类型 文件类型信息包含在 struct stat 里的 st_mode 成员 (1)普通文件,unix内核并不区分文本文件和二进制文件 (2)目录文件,这种文件包含了其他文件的名字以及指向这 ...

  8. Filter里面实现未登录跳转,已登录权限判断

    package com.erichfund.cljjfof.server.util; import java.io.IOException; /** * @author 作者 zhuzhengquan ...

  9. 43深入理解C指针之---指针与树

    一.size_t:用于安全表示长度,所有平台和系统都会解析成自己对应的长度 1.定义:size_t类型表示C中任何对象所能表示的最大长度,是个无符号整数:常常定义在stdio.h或stdlib.h中 ...

  10. vsCode 开发微信小程序插件

    用 vsCode 开发微信小程序可以配置以下插件,让开发更美好: 1. vscode weapp api 2. vscode wxml 3. vscode-wechat 4. Easy WXLESS ...