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

    并查集  要判断这个图是连通的 就是只有一个父节点 #include <cstdio> #include <cstring> #define maxn 100005 int f ...

  2. URAL 1353 Milliard Vasya's Function(DP)

    题目链接 题意 : 让你找出1到10^9中和为s的数有多少个. 思路 : 自己没想出来,看的题解,学长的题解报告 题解报告 //URAL 1353 #include <iostream> ...

  3. linux ubuntu 11.04 samba 服务器设置

    安装 SAMBA 组件 sudo apt-get install samba smbfs smbclient   配置相关参数 sudo gedit /etc/samba/smb.conf 文件中相关 ...

  4. linux 深入检测io详情的工具iopp

    1.为什么推荐iopp iotop对内核及python版本都有一定要求,有时候无法用上,这时候就可以使用iopp作为替代方案.在有些情况下可能无法顺利使用iotop,这时候就可以选择iopp了.它的作 ...

  5. 看文档要看仔细,英语要加强啊... cocos2d-x 的 API 和 对应版本的 cocos2d-js 的 API 没有完全对应

    /** * Sets the X rotation (angle) of the node in degrees which performs a horizontal rotational skew ...

  6. 不同VLAN之间互相通信

    前话 我们经常到机房上课,想必对机房后面那层叠的跟DVD一样的机器有印象吧,那些就是交换机. 交换机作用是什么? 我这里度娘一下: 交换机(Switch)意为"开关"是一种用于电( ...

  7. Google Code Style

    Google开源项目的代码遵循的规范,见这,C++, OC. PS: vim的配色编辑用户主目录下的.vimrc即可.

  8. Android安全问题 抢先开机启动

    导读:我们以如何抢先开机启动为例,来说明接收无序广播的静态广播接收器的接收顺序 (注意,文本只是陈述结果,所以叫结果篇,之后的文章再给出源码分析) 首先先说一下android中的广播和广播接收器 广播 ...

  9. 简单的神经元算法实现(python)

    参考python代码如下 #perceptron x=[[1 ,0, 0],[1,0,1],[1, 1, 0],[1, 1, 1],[0,0,1],[0,1,0],[0,1,1],[0,0,0]] y ...

  10. semantic versioning语义化版本号

    语义化版本号 是由github创始人 Tom Preston-Werner 发起的一个关于软件版本号的命名规范,关于这个规范详细的说明可以在 官网 查看,也可访问其 GitHub项目页面 ,官网文档: ...