题目链接: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. Spring boot&Mybatis 启动报错 Failed to auto-configure a DataSource

    *************************** APPLICATION FAILED TO START *************************** Description: Fai ...

  2. webpack 常用插件及作用

    copy-webpack-plugin :复制文件到目标文件夹.在开发时使用热模替换,(没有生成dist 文件夹,都在内存中),如果想引用某一个js文件,直接写script标签是找不到的,因为服务器内 ...

  3. 第八章 高级搜索树 (xa1)红黑树:动机

  4. 控制span的width属性及display属性值的选择

    给span设置width样式,会发现并没有改变它的宽度,但有时候我们需要给它设置固定的宽度,那么就可以设置它的display样式,改变span的显示模式就好了. span默认显示模式是inline,无 ...

  5. K组翻转链表 · Reverse Nodes in k-Group

    [抄题]: 给你一个链表以及一个k,将这个链表从头指针开始每k个翻转一下.链表元素个数不是k的倍数,最后剩余的不用翻转. [思维问题]: [一句话思路]: // reverse head->n1 ...

  6. Python3自动化运维

    一.系统基础信息模块详解 点击链接查看:https://www.cnblogs.com/hwlong/p/9084576.html 二.业务服务监控详解 点击链接查看:https://www.cnbl ...

  7. AssemblyVersion,AssemblyFileVersion解释以及获取

    简而言之,AssemblyVersion: 是程序集的版本,.NET的CLR用,用于标识出该dll的版本信息,用于定义强名称的版本号: AssemblyFileVersion: 为编译器生成的文件加入 ...

  8. 【原创】有关Silverlight中异常“XmalParseEception” 通用解决思路

    针对于 此类 XamlParse问题,大部分都是 silverlight/WPF 前段 xmal文件问题,仔细逐行审查 接口解决.

  9. Golang之beego读取配置信息,输出log模块

    1,准备好配置文件 [server] listen_ip = "0.0.0.0" listen_port = [logs] log_level=debug log_path=./l ...

  10. Connecting to MQSeries with .NET

    By connecting to MQSeries withing a .NET application, first it has to be done is to install MQ Serie ...