题目链接: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(线段树,区间修改)的更多相关文章

  1. E - Just a Hook HDU - 1698 线段树区间修改区间和模版题

    题意  给出一段初始化全为1的区间  后面可以一段一段更改成 1 或 2 或3 问最后整段区间的和是多少 思路:标准线段树区间和模版题 #include<cstdio> #include& ...

  2. HDU - 1698 线段树区间修改,区间查询

    这就是很简单的基本的线段树的基本操作,区间修改,区间查询,对区间内部信息打上laze标记,然后维护即可. 我自己做的时候太傻逼了...把区间修改写错了,对给定区间进行修改的时候,mid取的是节点的左右 ...

  3. Hdu 1698(线段树 区间修改 区间查询)

    In the game of DotA, Pudge's meat hook is actually the most horrible thing for most of the heroes. T ...

  4. hdu 1698 线段树 区间修改

    #include <cstdio> #include <cstdlib> #include <cmath> #include <map> #includ ...

  5. HDU 1698 线段树 区间更新求和

    一开始这条链子全都是1 #include<stdio.h> #include<string.h> #include<algorithm> #include<m ...

  6. hdu 1698 线段树 区间更新 区间求和

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

  7. HDU(1698),线段树区间更新

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698 区间更新重点在于懒惰标记. 当你更新的区间就是整个区间的时候,直接sum[rt] = c*(r- ...

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

    有m个操作,每个操作 X Y Z是将区间[X, Y]中的所有的数全部变为Z,最后询问整个区间所有数之和是多少. 区间更新有一个懒惰标记,set[o] = v,表示这个区间所有的数都是v,只有这个区间被 ...

  9. HDU 3397 线段树区间修改

    Sequence operation Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  10. Just a Hook HDU - 1698Just a Hook HDU - 1698 线段树区间替换

    #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> us ...

随机推荐

  1. Mysql 触发器 A表记录到B表

    1:查询出需要的列名 备用 #列名 select COLUMN_NAME from information_schema.columns where TABLE_SCHEMA='yunpiaobox_ ...

  2. Qt使用MSVC编译器不能正确显示中文的解决方案

    用VisualStudio做为IDE,使用Qt框架,显示中文,会出现乱码的情况. 原因:MSVC编译器虽然可以正常编译带BOM的UTF-8编译的源文件,但是生成的可执行文件的编码是Windows本地字 ...

  3. java web 跨域

    服务器端解决跨域问题的三种方法   跨域是指html文件所在的服务器与ajax请求的服务器是不同的ip+port,例如: - ‘192.168.1.1:8080’ 与 ‘192.168.1.2:808 ...

  4. JAVA WEB开发中的资源国际化

    为什么要国际化? 不同国家与地区语言,文化,生活习惯等差异.在数字,时间,语言,货币,日期,百分数等的不同. 两个名词: I18N:即资源国际化,全称为Internationalization,因为首 ...

  5. js数组类型判断与数据类型判断回顾

    判断一个对象是否是数组方法有多种: 一.Array.isArray()函数 在ECMAScript5中可以通过Array.isArray()来做这件事: Array.isArray({}); //fa ...

  6. 定制sudo的密码保持时间以及如何不需要密码

    由于每次sudo什么都要输入密码..好麻烦.所以我要把它的密码记住时间修改一下,变得长一点. 先输入命令 vim /etc/sudoers找到下面行 Defaults env_reset 改变此行为下 ...

  7. 了解innodb_support_xa(分布式事务)

    innodb_support_xa可以开关InnoDB的xa两段式事务提交.默认情况下,innodb_support_xa=true,支持xa两段式事务提交.此时MySQL首先要求innodb pre ...

  8. hadoop 集群安装配置 【转】

    http://www.cnblogs.com/ejiyuan/p/5557061.html 注意:要把master 上所有的配置文件(主要是配置的那四个 xxxx-site.xml 和 xxx-env ...

  9. 如何设置maven的local repository目录

    step1:默认会放在~/.m2/repository目录下 (“~”代表用户的目录,比如windows下一般都是C:\Documents and Settings\[你的用户名]\.由于“Docum ...

  10. cdoj841-休生伤杜景死惊开 (逆序数变形)【线段树 树状数组】

    http://acm.uestc.edu.cn/#/problem/show/841 休生伤杜景死惊开 Time Limit: 3000/1000MS (Java/Others)     Memory ...