#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+;
int n;
int c[maxn];
int lowbit(int x) { return x&(-x); }
void update(int num,int val)
{
while(num)
{
c[num]+=val;
num-=lowbit(num);
}
}
int getsum(int num)
{
int sum=;
while(num<=n)
{
sum+=c[num];
num+=lowbit(num);
}
return sum;
}
int32_t main()
{
while()
{
cin>>n;
if(n==) break;
memset(c,,sizeof(c));
for(int i=;i<=n;i++)
{
int a,b; cin>>a>>b;
update(b,);
update(a-,-);
}
for(int i=;i<=n;i++)
{
cout<<getsum(i);
if(i!=n) cout<<" ";
}cout<<endl;
}
}

hdu 1556 树状数组

hdu 1556 A - Color the ball 数状数组做法的更多相关文章

  1. HDOJ/HDU 1556 Color the ball(树状数组)

    Problem Description N个气球排成一排,从左到右依次编号为1,2,3-.N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"牌电动车从 ...

  2. HDU 1556 Color the ball (树状数组区间更新)

    水题,练习一下树状数组实现区间更新. 对于每个区间,区间左端点+1,右端点的后一位-1,查询每个位置的覆盖次数 #include <cstdio> #include <cstring ...

  3. Color the ball(树状数组+线段树+二分)

    Color the ball Time Limit : 9000/3000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Tota ...

  4. HDU 1556 Color the ball 树状数组 题解

    Problem Description N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"牌电动 ...

  5. hdu 1556 A - Color the ball 其他做法

    #include<bits/stdc++.h> using namespace std; ; int c[maxn]; int n; int main() { ) { cin>> ...

  6. HDU 1166 敌兵布阵 (数状数组,或线段树)

    题意:... 析:可以直接用数状数组进行模拟,也可以用线段树. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000&quo ...

  7. hdu 5869 区间不同GCD个数(树状数组)

    Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

  8. poj 2481 Cows(数状数组 或 线段树)

    题意:对于两个区间,[si,ei] 和 [sj,ej],若 si <= sj and ei >= ej and ei - si > ej - sj 则说明区间 [si,ei] 比 [ ...

  9. hdu 6203 ping ping ping(LCA+树状数组)

    hdu 6203 ping ping ping(LCA+树状数组) 题意:给一棵树,有m条路径,问至少删除多少个点使得这些路径都不连通 \(1 <= n <= 1e4\) \(1 < ...

随机推荐

  1. mongodb细节

    MongoDB中数值型默认为Double,可以使用NumberInt()函数及NumberLong()函数分别指定某个字段为整型和长整型.

  2. 解决Tomcat v6.0 Server at localhost was unable to start within 45 seconds

    eclipse 中tomcat启动超时报错如下: Starting Tomcat v7.0 Server at localhost' has encountered a problem Server ...

  3. 【原创】paintEvent()函数显示文本

    [代码] void MainWindow::paintEvent(QPaintEvent*) { QPainter p(this); QRect r; p.setPen(Qt::red); p.dra ...

  4. centos7 新装系统网络配置

    [root@localhost ~]# cat /etc/sysconfig/grub GRUB_TIMEOUT= GRUB_DISTRIBUTOR="$(sed 's, release . ...

  5. springMVC操作cookie和session

    cookie相关说明: 1.cookie由服务器端创建,然后添加到HttpServletResponse中发送给客户端(浏览器). 2.可以添加多个cookie键值对. 3.cookie由键值名和键值 ...

  6. 升级pip10.0.0后出现ModuleNotFoundError: No module named 'pip'的问题

    pip10升级后各种pip install出错----- Traceback (most recent call last): File "/usr/local/bin/pip", ...

  7. MII接口介绍(转)

    1.简介 MII (Media Independent Interface(介质无关接口)或称为媒体独立接口,它是IEEE-802.3定义的以太网行业标准.它包括一个数据接口和一个MAC和PHY之间的 ...

  8. POJ - 1942 D - Paths on a Grid

    Imagine you are attending your math lesson at school. Once again, you are bored because your teacher ...

  9. AndroidSDK 自带定位工具 uiautomatorviewer

    前言:uiautomatorviewer是androidSDK自带的定位工具 1.打开目录D:\Android\androidSDK\tools\bin 2.点击启动uiautomator,页面显示如 ...

  10. 解决Could not open Hibernate Session for transaction; nested exception is java.lang.NoClassDefFoundError: org/hibernate/engine/transaction/spi/TransactionContext

    我使用的是5.2.8的hibernate的jar包,运行的时候却报错Could not open Hibernate Session for transaction; nested exception ...