hdu 1698区间延迟更新
#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;
}
hdu 1698区间延迟更新的更多相关文章
- HDU 1698 区间更新
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- hdu 1556 线段树区间延迟更新好题
656mS #include<stdio.h> #include<stdlib.h> #define N 110000 struct node { int x,y,yanchi ...
- poj3468区间延迟更新模板题
#include<stdio.h> #include<string.h> #define N 100000 struct st{ int x,y; __int64 yanc ...
- HDU 1698 Just a Hook(线段树区间替换)
题目地址:pid=1698">HDU 1698 区间替换裸题.相同利用lazy延迟标记数组,这里仅仅是当lazy下放的时候把以下的lazy也所有改成lazy就好了. 代码例如以下: # ...
- hdu 1698 线段数的区间更新 以及延迟更新
先说说区间更新和单点更新的区别 主要的区别是搜索的过程 前者需要确定一个区间 后者就是一个点就好了 贴上两者代码 void updata(int i)//单点更新 { int l=stu[i].l; ...
- HDU 1698 Just a Hook (线段树区间更新)
题目链接 题意 : 一个有n段长的金属棍,开始都涂上铜,分段涂成别的,金的值是3,银的值是2,铜的值是1,然后问你最后这n段总共的值是多少. 思路 : 线段树的区间更新.可以理解为线段树成段更新的模板 ...
- HDU(1698),线段树区间更新
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1698 区间更新重点在于懒惰标记. 当你更新的区间就是整个区间的时候,直接sum[rt] = c*(r- ...
- HDU 1698 Just a Hook(线段树/区间更新)
题目链接: 传送门 Minimum Inversion Number Time Limit: 1000MS Memory Limit: 32768 K Description In the g ...
- HDU 1698 Just a Hook(线段树成段更新)
题目网址:http://acm.hdu.edu.cn/showproblem.php?pid=1698 题目: Problem Description In the game of DotA, P ...
随机推荐
- http的请求与响应-----content-type
content-type 指请求消息头的中请求消息数据的格式 有三种用法 第一种:设置在request header的参数中 js中可以在发送请求前在请求消息头中设置content-typevar x ...
- HttpWebRequest 以及WebRequest的使用
1.WebRequest的发送数据以及接收数据 class Program { static void Main(string[] args) { //创建一个实例并发送请求 HttpWebReque ...
- 锐动SDK置于社区沙龙
北京锐动天地信息技术有限公司成立于2007年9月.多年来一直专注于音视频领域核心技术的研发, 拥有Windows.iOS.Android全平台自主知识产权的领先技术产品. 2011年获得新浪战略投资, ...
- 11 Hash tables
11 Hash tables Many applications require a dynamic set that supports only the dictionary operatio ...
- java 文件另存为
FileUtils.copyFile(new File(), new File());
- github修改仓库项目的语言类型
github是 采用Linguist来自动识别你的代码应该归为哪一类. 解决方法: 我们可以在仓库的根目录下添加.gitattributes文件: ## 使用 `.gitattributes` 配置文 ...
- iTOP-4412开发板-实战教程-ssh服务器移植到arm开发板
本文转自迅为开发板:http://www.topeetboard.com 在前面实战教程中,移植了“串口文件传输工具”,整个移植过程是比较简单的,而且我 们没有做任何协议方面的了解,只是“配置”+“编 ...
- IE浏览器样式表限制
原文链接:http://caibaojian.com/ie-stylesheet.html 在开发头条上发现的IE浏览器样式限制,算是一个IE浏览器的一个bug吧.主要有4点限制:· IE9及以下单个 ...
- fedora27安装ssh
Fedora安装sshd 先确认是否已安装ssh服务: [root@localhost ~]# rpm -qa | grep openssh-server openssh-server-5.3p1-1 ...
- 360浏览器 收藏夹 ico 缓存 目录
C:\Users\Administrator\AppData\Roaming\360se6\apps\data\users\default\data\ico