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 ...
随机推荐
- 调用css文件,进行调色
Title 小米 <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...
- javascript时间日期操作
Js获取当前日期时间及其它操作 var myDate = new Date();myDate.getYear(); //获取当前年份(2位)myDate.getFullYear(); ...
- mouseenter 事件
定义和用法 当鼠标指针穿过元素时,会发生 mouseenter 事件. 该事件大多数时候会与 mouseleave 事件一起使用. mouseenter() 方法触发 mouseenter 事件,或规 ...
- rem 响应 js函数
size();window.onresize = function(){ size();}function size(){ var htnl_o=document.getElementsByTagNa ...
- XmlHttpRequest对象 ajax核心之一
XMLHttpRequest 对象 XML XSLT XML 解析器 XMLHttpRequest 对象用于在后台与服务器交换数据. 什么是 XMLHttpRequest 对象? XMLHttpReq ...
- How to Pronounce ‘to the’ in a Sentence
How to Pronounce ‘to the’ in a Sentence Share Tweet Share Tagged With: The Word THE, TO Reduction St ...
- 吴裕雄 实战PYTHON编程(5)
text = '中华'print(type(text))#<class 'str'>text1 = text.encode('gbk')print(type(text1))#<cla ...
- dp-最长公共子序列
最长公共子序列(NYOJ36) 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 咱们就不拐弯抹角了,如题,需要你做的就是写一个程序,得出最长公共子序列.tip:最长公 ...
- IDEA kotlin 配置
修改 idea 安装目录 bin 目录 下 idea.properties 文件修改idea.max.intellisense.filesize=50000 避免proto 生成的java文件不被 ...
- Centos7 配置ssh 免秘钥登陆
1.yum install -y openssh 2.servier1: ssh-keygen -t rsa #有提示的直接enter 3.server 2: ssh-keygen -t rsa # ...