hdu 1556 线段树区间延迟更新好题
656mS
#include<stdio.h>
#include<stdlib.h>
#define N 110000
struct node {
int x,y,yanchi,sum;
}a[N*10];
void build(int t,int x,int y) {
a[t].x=x;
a[t].y=y;
a[t].sum=0;
a[t].yanchi=0;
if(x==y)return ;
int temp=t*2;
int mid=(a[t].x+a[t].y)/2;
build(temp,x,mid);
build(temp+1,mid+1,y);
return ;
}
void inset(int t,int x,int y) {
if(a[t].x==x&&a[t].y==y) {
a[t].yanchi+=1;
return ;
}
int temp=t*2;
int mid=(a[t].x+a[t].y)/2;
if(x>mid)
inset(temp+1,x,y);
else
if(y<=mid)
inset(temp,x,y);
else {
inset(temp,x,mid);
inset(temp+1,mid+1,y);
}
return ;
}
int qury(int t,int x) {
if(a[t].x==a[t].y&&a[t].x==x)
return a[t].sum=a[t].sum+a[t].yanchi;
int temp=t*2;
int mid=(a[t].x+a[t].y)/2;
a[temp].yanchi+=a[t].yanchi;
a[temp+1].yanchi+=a[t].yanchi;
a[t].yanchi=0;
if(x>mid)
return qury(temp+1,x);
else
if(x<=mid)
return qury(temp,x);
}
int main() {
int n,i,start,end;
while(scanf("%d",&n),n) {
build(1,1,n);
for(i=1;i<=n;i++) {
scanf("%d%d",&start,&end);
inset(1,start,end);
}
for(i=1;i<n;i++)
printf("%d ",qury(1,i));
printf("%d\n",qury(1,n));
}
return 0;
}
hdu 1556 线段树区间延迟更新好题的更多相关文章
- hdu 5475 An easy problem(暴力 || 线段树区间单点更新)
http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...
- HDU 1698 线段树 区间更新求和
一开始这条链子全都是1 #include<stdio.h> #include<string.h> #include<algorithm> #include<m ...
- hdu 1698 线段树 区间更新 区间求和
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total ...
- (线段树 区间合并更新)Tunnel Warfare --hdu --1540
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1540 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- HDU 3911 线段树区间合并、异或取反操作
题目:http://acm.hdu.edu.cn/showproblem.php?pid=3911 线段树区间合并的题目,解释一下代码中声明数组的作用: m1是区间内连续1的最长长度,m0是区间内连续 ...
- hdu 3308(线段树区间合并)
LCIS Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- E - Just a Hook HDU - 1698 线段树区间修改区间和模版题
题意 给出一段初始化全为1的区间 后面可以一段一段更改成 1 或 2 或3 问最后整段区间的和是多少 思路:标准线段树区间和模版题 #include<cstdio> #include& ...
- HDU 3911 线段树区间合并
北京赛区快了,准备袭击数据结构和图论.倒计时 18天,线段树区间合并.维护一个最长连续.. 题意:给一个01串,以下有一些操作,问区间最长的连续的1的个数 思路:非常裸的线段树区间合并 #includ ...
- HDU 1556 线段树/树状数组/区间更新姿势 三种方法处理
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
随机推荐
- 开源前夕先给大家赞赏一下我用C语言开发的云贴吧 站点自己主动兼容-移动、手机、PC自己主动兼容云贴吧
开源前夕先给大家赞赏一下我用C语言开发的移动.手机.PC自己主动兼容云贴吧 - 涨知识属马超懒散,属虎太倔强.十二生肖全了!-转自云寻觅贴吧 转: 涨知识属马超懒散,属虎太倔强.十二生肖全了! -转自 ...
- h5-10 canvas 简易祖玛
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- js设计模式-门面模式
适用场景:门面模式在DOM脚本编程这种需要对各种不一致的浏览器接口的环境中很常用. 例子:阻止模式事件 var DED = widow.DED || {}; DED.util = { stopProp ...
- 随时随地日志Debug
对于一个应用程序而言,Log必不可少,但是有些时候仅仅想看下输出,如果加log的话就显得比较麻烦,这个时候就用到了Debug.WriteLine("测试下,你好,非常棒,牛叉!") ...
- WPF 漏斗控件 等待沙漏效果
由于WPF中不支持gif图片因此要实现一个漏斗沙漏效果有点小麻烦. 网上有一款开源的控件 理论上完全开源 官网 http://wpfspark.codeplex.com/贴一下效果图 大家感觉需要就在 ...
- MAVEN学习笔记之Maven生命周期和插件简介(3)
MAVEN学习笔记之Maven生命周期和插件简介(3) clean compile site三套生命周期相互独立. clean pre-clean 执行清理前的工作 clean 清理上一次构建生成的所 ...
- String[]转化暴露“思维误区”
那天写code,用到这个,强转,将页面传来的值转换为数组,结果是,当页面传来的只有一个值时,它是无法转换为数组的,只能获得1个string,只有length>1时才会转化为数组的形式,报的错误是 ...
- 编码和解码(字符串与byte[]之间的转换)
资源来自互联网http://www.cnblogs.com/dabaopku/archive/2012/02/27/2370446.html 非常蛋疼的事情, google 和 baidu 在编码是分 ...
- matplotlib学习笔记.CookBook
matplotlib 是Python下的一个高质量的画图库,可以简单的类似于MATLAB方法构建高质量的图表. 原始文章地址:http://zanyongli.i.sohu.com/blog/view ...
- spring cloud(四) feign
spring cloud 使用feign进行服务间调用 1. 新建boot工程 pom引入依赖 <dependency> <groupId>org.springframewor ...