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. Unity3d数据加密

    在unity中能够使用c#自带的对称算法对数据进行加密,以下两种加密算法: using System; using System.Text; using System.Security.Cryptog ...

  2. bzoj5194: [Usaco2018 Feb]Snow Boots

    还真是.. 就是 一个被不点名批评的垃圾骗分暴力选手被普及难度的省选信心(??)模拟赛艹爆的题解 的t3嘛... #include<cstdio> #include<iostream ...

  3. Task.ConfigureAwait

    public ConfiguredTaskAwaitable ConfigureAwait( bool continueOnCapturedContext ) Configures an awaite ...

  4. React-Native Android开发沉思录

    在runServer.js中有声明如何启动http服务: 查看端口占用情况 而且在系统管理器中,根本找不到PID为7956的应用,那能更改端口吗?在server.js中有声明: module.expo ...

  5. 关于c-string类

    特别鸣谢:由张老师整理(原出处未知 一.C++ 字符串 C++ 提供了以下两种类型的字符串表示形式: C 风格字符串 C++ 引入的 string 类类型 1.C 风格字符串 C 风格的字符串起源于 ...

  6. Ubuntu搭建docker环境

    一丶自己搭建Ubuntu的虚拟机(网上很多教程) PS:下带图形化界面的Ubuntu镜像,这里只说一下要装那些工具和做那些配置   安装vim         sudo apt-get install ...

  7. JWT和Spring Security集成

    通常情况下,把API直接暴露出去是风险很大的, 我们一般需要对API划分出一定的权限级别,然后做一个用户的鉴权,依据鉴权结果给予用户对应的API (一)JWT是什么,为什么要使用它? 互联网服务离不开 ...

  8. LeetCode Weekly Contest 24

    1, 543. Diameter of Binary Tree 维护左右子树的高度,同时更新结果,返回以该节点结束的最大长度.递归调用. /** * Definition for a binary t ...

  9. C# CultureInfo.InvariantCulture

    今天在写代码的过程中发现了一个有意思的问题,我在写了一个日期格式转化的时候发现不同电脑的运行结果不一致. 代码如下 string str = this.tbTime.Text; if(string.I ...

  10. html中DTD使用小结

    DTD 是一套关于标记符的语法规则.它是XML1.0版规格得一部分,是html文件的验证机制,属于html文件组成的一部分. DTD:三种文档类型:S(Strict).T(Transitional). ...