题目地址:

pid=1698">HDU 1698

区间替换裸题。相同利用lazy延迟标记数组,这里仅仅是当lazy下放的时候把以下的lazy也所有改成lazy就好了。

代码例如以下:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include <algorithm> using namespace std;
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1
const int MAXN=1e5+10;
int sum[MAXN<<3], lazy[MAXN<<3];
void PushUp(int rt)
{
sum[rt]=sum[rt<<1]+sum[rt<<1|1];
}
void PushDown(int rt, int m)
{
if(lazy[rt])
{
lazy[rt<<1]=lazy[rt<<1|1]=lazy[rt];
sum[rt<<1]=lazy[rt]*(m-(m>>1));
sum[rt<<1|1]=lazy[rt]*(m>>1);
lazy[rt]=0;
}
}
void build(int l, int r, int rt)
{
lazy[rt]=0;
if(l==r)
{
sum[rt]=1;
return ;
}
int mid=l+r>>1;
build(lson);
build(rson);
PushUp(rt);
}
void update(int ll, int rr, int x, int l, int r, int rt)
{
if(ll<=l&&rr>=r)
{
lazy[rt]=x;
sum[rt]=(r-l+1)*x;
return ;
}
PushDown(rt, r-l+1);
int mid=l+r>>1;
if(ll<=mid) update(ll,rr,x,lson);
if(rr>mid) update(ll,rr,x,rson);
PushUp(rt);
}
int main()
{
int n, i, a, b, c, t, q, num=0;
scanf("%d",&t);
while(t--)
{
num++;
scanf("%d",&n);
build(1,n,1);
scanf("%d",&q);
while(q--)
{
scanf("%d%d%d",&a,&b,&c);
update(a,b,c,1,n,1);
}
printf("Case %d: The total value of the hook is %d.\n",num,sum[1]);
}
return 0;
}

最新文章

  1. &quot;转&quot; CXF+JAXB处理复杂数据
  2. 【CodeForces 698A】Vacations
  3. WIN7系统下U盘安装Ubuntu双系统
  4. Android API中常用的包(转)
  5. ASP.NET MVC5 高级编程 第2章 控制器
  6. php-cli模式学习(PHP命令行模式)(转)
  7. NLP自然语言处理学习笔记二(初试)
  8. iOS block并发
  9. Android切换页面--setContentView
  10. WCF(二)三种通信模式
  11. windows 服务的安装与卸载之bat脚本命令
  12. 【网络安全】SSLSplit实现中间人攻击
  13. python day19--面向对象,接口,封装
  14. Http 概述
  15. Android自定义权限
  16. webgl,threejs教程、笔记
  17. Hadoop 和 Spark 的关系
  18. 转:oracle:win7手工卸载oracle数据库11g
  19. 到底该用img还是background-image?
  20. 【服务器防护】linux 如何查看防火墙是否开启

热门文章

  1. (英文排版测试)Lorem Ipsum
  2. P2564 生日礼物
  3. Linux Shell系列教程之(十)Shell for循环
  4. HDU——2067小兔的棋盘(卡特兰数&amp;递推DP)
  5. scrapy的调试方法
  6. Python ping 模块
  7. 洛谷P1236 算24点
  8. 【CF721C】Journey(拓扑排序,最短路,DP)
  9. touch上滑加载
  10. 关于Dijkstra 和 Bellman-ford算法的简单理解