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 线段树区间延迟更新好题的更多相关文章

  1. hdu 5475 An easy problem(暴力 || 线段树区间单点更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...

  2. HDU 1698 线段树 区间更新求和

    一开始这条链子全都是1 #include<stdio.h> #include<string.h> #include<algorithm> #include<m ...

  3. hdu 1698 线段树 区间更新 区间求和

    Just a Hook Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  4. (线段树 区间合并更新)Tunnel Warfare --hdu --1540

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1540 http://acm.hust.edu.cn/vjudge/contest/view.action ...

  5. HDU 3911 线段树区间合并、异或取反操作

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=3911 线段树区间合并的题目,解释一下代码中声明数组的作用: m1是区间内连续1的最长长度,m0是区间内连续 ...

  6. hdu 3308(线段树区间合并)

    LCIS Time Limit: 6000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submis ...

  7. E - Just a Hook HDU - 1698 线段树区间修改区间和模版题

    题意  给出一段初始化全为1的区间  后面可以一段一段更改成 1 或 2 或3 问最后整段区间的和是多少 思路:标准线段树区间和模版题 #include<cstdio> #include& ...

  8. HDU 3911 线段树区间合并

    北京赛区快了,准备袭击数据结构和图论.倒计时 18天,线段树区间合并.维护一个最长连续.. 题意:给一个01串,以下有一些操作,问区间最长的连续的1的个数 思路:非常裸的线段树区间合并 #includ ...

  9. HDU 1556 线段树/树状数组/区间更新姿势 三种方法处理

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

随机推荐

  1. leetcode解题文件夹

    点击打开链接点击打开链接点击打开链接參考文献:http://blog.csdn.net/lanxu_yy/article/details/17848219 只是本文准备用超链接的方式连接到对应解答页面 ...

  2. ios swift学习日记4-字符串和字符

    近期ios的swift语言好像火了起来,本人没有objectc的基础,但之前是有c跟java的基础的. 从这几天開始学习ios的swift语言,后期以博客形式公布.这里提供一本翻译的英文版的swif书 ...

  3. luogu1313 计算系数

    题目大意:给定一个多项式(ax+by)^k,请求出多项式展开后x^n*y^m 项的系数. 将原式化为(ax+by)*(ax+by)*...①,然后将其拆解,拆解时x乘了多少次,a就乘了多少次,y,b同 ...

  4. vim设置solarized配色

    最近在学习使用VIM.我选择Solarized配色.相信很多人也都在用. 官网地址: http://ethanschoonover.com/solarized 看这配色:八卦乾坤,赏心悦目,高端大气上 ...

  5. php传值调用和传值调用和变量函数

    php传值调用和传值调用和变量函数 代码 <?php //传值调用,$m的值不改变 function text($i){ $i = 'Clive'; echo $i; } text(123); ...

  6. The Triangle--nyoj 18

    The Triangle 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 7 3 8 8 1 0 2 7 4 4 4 5 2 6 5 (Figure 1) Figure ...

  7. EOJ 1113 装箱问题

    有一个箱子容量为 V (正整数,0≤V≤20000),同时有 n 个物品(0<n≤30),每个物品有一个体积(正整数).要求从 n 个物品中,任取若干个装入箱内,使箱子的剩余空间为最小. Inp ...

  8. WPF中StringToImage和BoolToImage简单用法

    在WPF的绑定控件操作中,经常会通过bool值或者某些特定的string值做出相应动作.但UI层控件的很多属性对应的都不是Bool值或者对应的只是固定的String值. 这个时候有两方法解决该问题. ...

  9. GStreamer基础教程02 - 基本概念

    摘要 在 Gstreamer基础教程01 - Hello World中,我们介绍了如何快速的通过一个字符串创建一个简单的pipeline.为了能够更好的控制pipline中的element,我们需要单 ...

  10. SilverLight Q&A

    1.在学校prism,Unity框架的时候,遇到的问题“The IModuleCatalog is required and cannot be null in order to initialize ...