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. 仿支付宝/微信的password输入框效果GridPasswordView解析

    仿支付宝/微信的password输入框效果GridPasswordView解析,把一些设置和一些关键的地方列了出来,方便大家使用,可能能够省一部分的时间,也算是自己的积累吧. 1.password框能 ...

  2. java封装AES加密算法

    在实际coding中会常常遇到往数据库存入密码时加密.URL传參时的加密.由此简单封装了下java中的AES加密算法. 0.import类 import java.security.SecureRan ...

  3. oc18--self1

    // // Iphone.h // day13 #import <Foundation/Foundation.h> typedef enum { kFlahlightStatusOpen, ...

  4. SQL注入原理解析以及举例1

    sql注入是指web应用程序对用户输入数据的合法性没有判断,导致攻击者可以构造不同的sql语句来实现对数据库的操作. sql注入漏洞产生满足条件: 1:用户能够控制数据的输入. 2:原本需要执行的代码 ...

  5. HBase编程 API入门系列之modify(管理端而言)(10)

    这里,我带领大家,学习更高级的,因为,在开发中,尽量不能去服务器上修改表. 所以,在管理端来修改HBase表.采用线程池的方式(也是生产开发里首推的) package zhouls.bigdata.H ...

  6. Npgsql使用入门(三)【批量导入数据】

    Program.cs代码: class Program { static void Main(string[] args) { var test = new PgBulkCopyHelper<S ...

  7. website robots.txt 防爬虫 措施

    robots.txt文件用法举例: 1. 允许所有的robot访问 User-agent: * Allow: / 或者 User-agent: * Disallow: 2. 禁止所有搜索引擎访问网站的 ...

  8. ts中类的继承

    定义类 class Person { name: string; //属性 constructor(_name: string) { this.name = _name; } //构造函数 sayHe ...

  9. USB接口大全

    USB2.0系列: Standard A: Standard B: Mini Standard B: Micro USB: ** Micro USB 与 Mini B比较 ** USB3.0系列: U ...

  10. MySQL_基本操作

    sql语句 Sql语句主要用于存取数据,查询数据,更新数据和管理数据库系统. #Sql语句分为3种类型 #1.DDL语句:数据库定义语言: 数据库.表.视图.索引.存储过程,例如CREATE DROP ...