hdu-1698(线段树,区间修改)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698
注意:用位运算会更快,不然超时。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn = ;
int a[maxn],lazy[maxn];
void pushdown(int k,int l,int r)
{
if(lazy[k])
{
lazy[k<<]=lazy[k];
lazy[k<<|]=lazy[k];
int mid=(l+r)>>;
a[k<<]=(mid-l+)*lazy[k];
a[k<<|]=(r-mid)*lazy[k];
lazy[k]=;
}
}
void build(int k,int l,int r)
{
lazy[k]=;
if(l==r)
{
a[k]=;
return ;
}
int mid=(l+r)>>;
build(k<<,l,mid);
build(k<<|,mid+,r);
a[k]=a[k<<]+a[k<<|];
}
void update(int k,int l,int r,int x,int y,int v)
{
if(x<=l&&y>=r)
{
lazy[k]=v;
a[k]=(r-l+)*v;
return ;
}
pushdown(k,l,r);
int mid=(l+r)>>;
if(x<=mid) update(k<<,l,mid,x,y,v);
if(y>mid) update(k<<|,mid+,r,x,y,v);
a[k]=a[k<<]+a[k<<|];
}
int query(int k,int l,int r,int x,int y)
{
if(x<=l&&y>=r) return a[k];
pushdown(k,l,r);
int mid=(l+r)>>;
int ans=;
if(x<=mid) ans+=query(k<<,l,mid,x,y);
if(y>mid) ans+=query(k<<|,mid+,r,x,y);
return ans;
}
int main(void)
{
int n,m,x,y,k,t,i,pt=;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&n,&m);
build(,,n);
for(i=;i<m;i++)
{
scanf("%d%d%d",&x,&y,&k);
update(,,n,x,y,k);
}
printf("Case %d: The total value of the hook is %d.\n",pt++,query(,,n,,n));
}
return ;
}
hdu-1698(线段树,区间修改)的更多相关文章
- E - Just a Hook HDU - 1698 线段树区间修改区间和模版题
题意 给出一段初始化全为1的区间 后面可以一段一段更改成 1 或 2 或3 问最后整段区间的和是多少 思路:标准线段树区间和模版题 #include<cstdio> #include& ...
- HDU - 1698 线段树区间修改,区间查询
这就是很简单的基本的线段树的基本操作,区间修改,区间查询,对区间内部信息打上laze标记,然后维护即可. 我自己做的时候太傻逼了...把区间修改写错了,对给定区间进行修改的时候,mid取的是节点的左右 ...
- Hdu 1698(线段树 区间修改 区间查询)
In the game of DotA, Pudge's meat hook is actually the most horrible thing for most of the heroes. T ...
- hdu 1698 线段树 区间修改
#include <cstdio> #include <cstdlib> #include <cmath> #include <map> #includ ...
- HDU 1698 线段树 区间更新求和
一开始这条链子全都是1 #include<stdio.h> #include<string.h> #include<algorithm> #include<m ...
- hdu 1698 线段树 区间更新 区间求和
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- HDU(1698),线段树区间更新
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698 区间更新重点在于懒惰标记. 当你更新的区间就是整个区间的时候,直接sum[rt] = c*(r- ...
- HDU 1698 (线段树 区间更新) Just a Hook
有m个操作,每个操作 X Y Z是将区间[X, Y]中的所有的数全部变为Z,最后询问整个区间所有数之和是多少. 区间更新有一个懒惰标记,set[o] = v,表示这个区间所有的数都是v,只有这个区间被 ...
- HDU 3397 线段树区间修改
Sequence operation Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- Just a Hook HDU - 1698Just a Hook HDU - 1698 线段树区间替换
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> us ...
随机推荐
- 数据报表之Excel操作模块
Excel是当今最流行的电子表格处理软件,支持丰富的计算函数及图表,在系统运营方面广泛用于运营数据报表,比如业务质量.资源利用.安全扫描等报表,同时也是应用系统常见的文件导出格式,以便数据使用人员做进 ...
- centos7 opencc 安装
繁体字转换:http://xh.5156edu.com/jtof.php 转换的有问题http://tool.lu/zhconvert/ git网址:https://github.com/BYVoid ...
- 大型运输行业实战_day09_2_站间互售实现
1.添加站间互售入口 对应的html代码 <button onclick="otherStation()">站间互售</button> 对应的js发送函数 ...
- java 用volatile和不用volatile的区别
在当前的Java内存模型下,线程可以把变量保存在本地内存(比如机器的寄存器)中,而不是直接在主存中进行读写.这就可能造成一个线程在主存中修改了一个变量的值,而另外一个线程还继续使用它在寄存器中的变量值 ...
- update from
update table1 set table1.column1 =(select table2.column1 from table2 where 关联条件) where exists(selec ...
- dhtmlx uploader使用
前端:{type : "upload", mode : "html4", name : "importFile", inputWidth : ...
- 第六章 图(b1)邻接矩阵
- codeblocks 更换颜色主题
关闭codeblocks,下载主题文件(colour_themes.conf).在关闭codeblocks的情况下,linux下的~/.config/codeblocks/下有个conf文件,将其备份 ...
- compression
compression - 必应词典 美[kəmˈpreʃ(ə)n]英[kəm'preʃ(ə)n] n.压缩:加压:压紧:浓缩 网络压迫:压力:加压包扎
- 解决Lightmap在PC上与ios和Android上表现不同的问题
Lightmap在PC上与android和ios的区别以及解决方法 1. 问题描述 相信很多人碰到过Lightmap的一些问题: 烘培好Lightmap之后,在PC上看起来相当给力,而打包成ios或 ...