lazy标记

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
const int N=;
const int MOD = 1e9+;
#define LL long long
double const pi = acos(-);
void fre() {
freopen("in.txt","r",stdin);
}
// inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// }
int n;
struct node{
int l,r,sum;
int lazy;
}tree[N<<]; void pushdown(int rt){
if(tree[rt].lazy!=){
tree[rt<<].lazy=tree[rt<<|].lazy=tree[rt].lazy;
tree[rt<<].sum=(tree[rt<<].r-tree[rt<<].l+)*tree[rt<<].lazy;
tree[rt<<|].sum=(tree[rt<<|].r-tree[rt<<|].l+)*tree[rt<<|].lazy;
tree[rt].lazy=;
}
} void updata(int l,int r,int x,int L,int R,int rt){
if(tree[rt].lazy==x) return;
if(l<=L&&r>=R){
tree[rt].lazy=x;
tree[rt].sum=x*(R-L+);
return;
}
pushdown(rt);
int mid=(L+R)>>;
if(r<=mid)
updata(l,r,x,L,mid,rt<<);
else if(l>mid)
updata(l,r,x,mid+,R,rt<<|);
else{
updata(l,r,x,L,mid,rt<<);
updata(l,r,x,mid+,R,rt<<|);
}
tree[rt].sum=tree[rt<<].sum+tree[rt<<|].sum;
return;
} void build(int l,int r,int rt){
tree[rt].l=l;
tree[rt].r=r;
tree[rt].lazy=;
if(l==r){
tree[rt].sum=;
return;
}
int mid=(l+r)>>;
build(l,mid,rt<<);
build(mid+,r,rt<<|);
tree[rt].sum=tree[rt<<].sum+tree[rt<<|].sum;
return;
} int main(){
// fre();
int T,q,l,r,x;
scanf("%d",&T);
int cas=;
while(T--){
scanf("%d",&n);
build(,n,);
// for(int i=1;i<=18;i++)
// {
// printf("%d\n",tree[i].sum);
// }
// getch();
scanf("%d",&q);
while(q--){
scanf("%d%d%d",&l,&r,&x);
updata(l,r,x,,n,);
// for(int i=1;i<=25;i++){
// printf("%d:%d\n",i,tree[i].sum);
// }
// system("pause");
}
printf("Case %d: The total value of the hook is %d.\n",cas++,tree[].sum);
}
return ;
}

HDU 1698 Just a Hook 区间更新 lazy标记的更多相关文章

  1. hdu 1698(线段树区间更新)

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

  2. hdu 1698 线段数的区间更新 以及延迟更新

    先说说区间更新和单点更新的区别 主要的区别是搜索的过程 前者需要确定一个区间 后者就是一个点就好了 贴上两者代码 void updata(int i)//单点更新 { int l=stu[i].l; ...

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

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

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

  5. HDU 3911 Black And White (线段树区间合并 + lazy标记)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3911 给你n个数0和1,m个操作: 0操作  输出l到r之间最长的连续1的个数 1操作  将l到r之间 ...

  6. hdu 4031 attack 线段树区间更新

    Attack Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Subm ...

  7. HDU 1698 Just a Hook (线段树区间更新)

    题目链接 题意 : 一个有n段长的金属棍,开始都涂上铜,分段涂成别的,金的值是3,银的值是2,铜的值是1,然后问你最后这n段总共的值是多少. 思路 : 线段树的区间更新.可以理解为线段树成段更新的模板 ...

  8. HDU 1698 Just a Hook(线段树:区间更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=1698 题意:给出1~n的数,每个数初始为1,每次改变[a,b]的值,最后求1~n的值之和. 思路: 区间更新题目 ...

  9. 暑期训练狂刷系列——Hdu 1698 Just a Hook (线段树区间更新)

    题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1698 题目大意: 有一个钩子有n条棍子组成,棍子有铜银金三种组成,价值分别为1,2,3.为了对付每场 ...

随机推荐

  1. Matlab中rand('state',sum(clock))解析

    一.问题来源 来自于一份PSO代码,PSO中需要初始化粒子位置和速度. 二.问题探究 众所周知,Matlab中的rand()函数产生的是伪随机数,但一般用来也可以接受.但是,如果我们知道伪随机数的初始 ...

  2. ENVI5.1安装破解教程

    原文地址:  ENVI5.1安装破解_百度经验 http://jingyan.baidu.com/article/020278118b5ded1bcd9ce57a.html   ENVI5.1_x86 ...

  3. WPF中通过代码定义模板

    WPF中可以再XAML中定义模板,也可以通过C#代码定义模板,通过代码可能更清楚的看清其逻辑,而且代码的好处就是可以随时动态的去操作,而在XAML中定义的一般都是静态的. //控件呈现的显示内容1(这 ...

  4. [译]Atomic VS. Non-Atomic 操作

    原文链接:atomic-vs-non-atomic-operations 在网上已经写了很多关于原子操作的文章,但是通常都集中在原子的读-修改-写(RMW. read-modify-write)操作. ...

  5. linux编译注解

    Linux kernel release 3.x <http://kernel.org/> These are the release notes for Linux version 3. ...

  6. WinCE下VPN设置

    一.环境 1.      WinCE5.0+2004/2005/2006/2007补丁. 2.      3G拨号模块. 二.说明 1.      WinCE设备必须可以接入网络. 2.      支 ...

  7. C#中的Marshal

    Const.MaxLengthOfBufferd的长度固定为0x2000   也就是8192 private bool SendMessage(int messageType, string ip, ...

  8. string.Join和string.Concat的区别

    源自Difference between String.Join() vs String.Concat() With .NET 4.0, String.Join() uses StringBuilde ...

  9. C语言字符串函数

    strtok()     字符串分割函数strstr()     字符串查找函数 范例 #include <string.h> main() {     char * s = " ...

  10. hdu4635Strongly connected

    http://acm.hdu.edu.cn/showproblem.php?pid=4635 tarjan缩点 统计缩点后每个结点的出度入度 将那个包含原来点数最少的 且出度或者入度为0的大节点看作一 ...