HDU 1698 Just a Hook(线段树区间替换)
2024-10-20 13:39:14
题目地址: 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;
}
最新文章
- ";转"; CXF+JAXB处理复杂数据
- 【CodeForces 698A】Vacations
- WIN7系统下U盘安装Ubuntu双系统
- Android API中常用的包(转)
- ASP.NET MVC5 高级编程 第2章 控制器
- php-cli模式学习(PHP命令行模式)(转)
- NLP自然语言处理学习笔记二(初试)
- iOS block并发
- Android切换页面--setContentView
- WCF(二)三种通信模式
- windows 服务的安装与卸载之bat脚本命令
- 【网络安全】SSLSplit实现中间人攻击
- python day19--面向对象,接口,封装
- Http 概述
- Android自定义权限
- webgl,threejs教程、笔记
- Hadoop 和 Spark 的关系
- 转:oracle:win7手工卸载oracle数据库11g
- 到底该用img还是background-image?
- 【服务器防护】linux 如何查看防火墙是否开启