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 ...
随机推荐
- redis之Hash存储与String存储内存消耗对照
存储对象User String存储方式: SET media:1155315 939 GET media:1155315 > 939 String结构存储该对象 User243 243600 存 ...
- luogu1120 小木棍【数据加强版】 暴力剪枝
题目大意 乔治有一些同样长的小木棍,他把这些木棍随意砍成几段,直到每段的长都不超过50.现在,他想把小木棍拼接成原来的样子,但是却忘记了自己开始时有多少根木棍和它们的长度.给出每段小木棍的长度,编程帮 ...
- 网络 - TCP/IP四层模型,面向生产
TCP.IP四层模型 (网络接口层,网际互联层,传输层,应用层.) (左边是车模,右边是实际生产的车.) 物理层,负责0101比特流传递. 数据链路层,MAC地址负责局域网,内网通信.MAC地址,由4 ...
- poj--1274--The Perfect Stall(最大匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21665 Accepted: 973 ...
- angular里使用vue/vue组件怎么在angular里用
欢迎加入前端交流群交流知识&&获取视频资料:749539640 如何在angularjs(1)中使用vue参考: https://medium.com/@graphicbeacon/h ...
- php 写日志函数(原创)
function write_log($msg,$isEcho=false,$path=''){ $path?'':$path='logs'.DIRECTORY_SEPARATOR.'log'.dat ...
- redis动态添加内存,动态配置,无需重启
在redis的使用过程中,有时候需要急需修改redis的配置,比如在业务运行的情况下,内存不够怎么办,这时要么赶紧删除无用的内存,要么扩展内存.如果有无用的内容可删除那么所有问题都已经解决.如果内容都 ...
- 24. Swap Nodes in Pairs[M]两两交换链表中的节点
题目 Given a linked list, swap every two adjacent nodes and return its head. You may not modify the va ...
- 使用autofac在mvc5下依赖注入
把遇到的问题汇总一下: 一.安装mvc5版本 命令:pm> Install-Package Autofac 结果安装的Autofac.Integration.Mvc(版本为4.0),所引用的依赖 ...
- ubuntu16.04 下载 fabric
1 Fabric源码下载 我们可以使用Git命令下载源码,也可以使用go get命令,偷懒一点,我们直接用go get命令获取最新的Fabric源码: go get github.com/hyperl ...