hdu 1698区间延迟更新
来源:互联网 发布:qsv转换mp4软件 编辑:程序博客网 时间:2024/05/16 08:11
#include<stdio.h>
#define N 100100
struct node {
int x,y,yanchi;
}a[N*4];//注意数组范围
void build(int t,int x,int y) {
a[t].x=x;
a[t].y=y;
a[t].yanchi=1;
if(x==y)
return ;
int temp=t<<1;
int mid=(x+y)/2;
build(temp,x,mid);
build(temp+1,mid+1,y);
}
void update(int t,int x,int y,int z) {
if(a[t].yanchi==z)
return ;
if(a[t].x==x&&a[t].y==y) {
a[t].yanchi=z;
return ;
}
int temp=t<<1;
if(a[t].yanchi!=-1) {
a[temp].yanchi=a[temp+1].yanchi=a[t].yanchi;
a[t].yanchi=-1;
}
int mid=(a[t].x+a[t].y)/2;
if(x>mid)
update(temp+1,x,y,z);
else
if(y<=mid)
update(temp,x,y,z);
else {
update(temp,x,mid,z);
update(temp+1,mid+1,y,z);
}
return ;
}
__int64 qury(int t) {
if(a[t].yanchi!=-1)
return (a[t].y-a[t].x+1)*a[t].yanchi;
else
return qury(t*2)+qury(t*2+1);
}
int main() {
int t,i,j,k,n,m,count=0;
scanf("%d",&t);
while(t--) {
scanf("%d",&n);
scanf("%d",&m);
build(1,1,n);
while(m--) {
scanf("%d%d%d",&i,&j,&k);
update(1,i,j,k);
}
printf("Case %d: The total value of the hook is %I64d.\n",++count,qury(1));//注意结果大小
}
return 0;
}
#define N 100100
struct node {
int x,y,yanchi;
}a[N*4];//注意数组范围
void build(int t,int x,int y) {
a[t].x=x;
a[t].y=y;
a[t].yanchi=1;
if(x==y)
return ;
int temp=t<<1;
int mid=(x+y)/2;
build(temp,x,mid);
build(temp+1,mid+1,y);
}
void update(int t,int x,int y,int z) {
if(a[t].yanchi==z)
return ;
if(a[t].x==x&&a[t].y==y) {
a[t].yanchi=z;
return ;
}
int temp=t<<1;
if(a[t].yanchi!=-1) {
a[temp].yanchi=a[temp+1].yanchi=a[t].yanchi;
a[t].yanchi=-1;
}
int mid=(a[t].x+a[t].y)/2;
if(x>mid)
update(temp+1,x,y,z);
else
if(y<=mid)
update(temp,x,y,z);
else {
update(temp,x,mid,z);
update(temp+1,mid+1,y,z);
}
return ;
}
__int64 qury(int t) {
if(a[t].yanchi!=-1)
return (a[t].y-a[t].x+1)*a[t].yanchi;
else
return qury(t*2)+qury(t*2+1);
}
int main() {
int t,i,j,k,n,m,count=0;
scanf("%d",&t);
while(t--) {
scanf("%d",&n);
scanf("%d",&m);
build(1,1,n);
while(m--) {
scanf("%d%d%d",&i,&j,&k);
update(1,i,j,k);
}
printf("Case %d: The total value of the hook is %I64d.\n",++count,qury(1));//注意结果大小
}
return 0;
}
- hdu 1698区间延迟更新
- hdu 1698 区间更新
- hdu 1698 区间更新
- 杭电 HDU ACM 1698 Just a Hook(线段树 区间更新 延迟标记)
- 【HDU 1698】Just a Hook 线段树 区间覆盖更新+延迟
- hdu 1556 线段树区间延迟更新好题
- hdu 1698 (延迟标记+区间修改+区间求和)
- HDU 1698 区间更新 求和
- hdu 1698 简单区间更新
- HDU 2871 Memory Control(线段树区间更新,延迟更新+vector+二分)
- 线段树区间更新模板(lazy延迟标记)(1698)
- HDU 1698 区间更新线段树
- hdu 1698 线段树区间更新
- HDU 1698 【线段树区间更新】
- HDU 1698(线段树区间更新)
- HDU-1698-Just a Hook-区间更新
- hdu 1698 线段树 区间更新
- HDU 1698 线段树区间更新模板
- AJAX.1.AJAX简介
- 数据库基础知识
- OC之文件管理NSFileHandle
- Mendeley不能首次登陆的解决办法
- NetBeans快捷键
- hdu 1698区间延迟更新
- ZOJ 3674 Search in the Wiki
- xor
- 高精度加减乘运算
- opencv学习-core结构学习
- opencv学习_14 (图像的尺度空间)
- typedef int (init_fnc_t) (void)和typedef int (*init_fnc_t) (void)
- http://uos-embedded.googlecode.com/svn/trunk/sources/runtime/memset-fast.c
- 岛上的植物