HDU 1556 Color the ball (数状数组)
Color the ball
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5397 Accepted Submission(s): 2882
当N = 0,输入结束。
1 1
2 2
3 3
3
1 1
1 2
1 3
0
3 2 1
#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; const int N=; int n,arr[N],level[N]; int lowbit(int x){
return x&(-x);
} void update(int i,int val){
while(i<=n){
arr[i]+=val;
i+=lowbit(i);
}
} int Sum(int i){
int ans=;
while(i>){
ans+=arr[i];
i-=lowbit(i);
}
return ans;
} int main(){ //freopen("input.txt","r",stdin); while(~scanf("%d",&n) && n){
memset(arr,,sizeof(arr));
memset(level,,sizeof(level));
int a,b;
for(int i=;i<=n;i++){
scanf("%d%d",&a,&b);
update(a,);
update(b+,-); //这两个函数刚好更新x~y之间的值都+1
}
for(int i=;i<n;i++)
printf("%d ",Sum(i));
printf("%d\n",Sum(n));
}
return ;
}
HDU 1556 Color the ball (数状数组)的更多相关文章
- HDOJ/HDU 1556 Color the ball(树状数组)
Problem Description N个气球排成一排,从左到右依次编号为1,2,3-.N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"牌电动车从 ...
- HDU 1556 Color the ball (树状数组区间更新)
水题,练习一下树状数组实现区间更新. 对于每个区间,区间左端点+1,右端点的后一位-1,查询每个位置的覆盖次数 #include <cstdio> #include <cstring ...
- HDU 1556 Color the ball 树状数组 题解
Problem Description N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"牌电动 ...
- hdu 1556 A - Color the ball 数状数组做法
#include<bits/stdc++.h> using namespace std; ; int n; int c[maxn]; int lowbit(int x) { return ...
- HDU 1556 Color the ball【差分数组裸题/模板】
N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"牌电动车从气球a开始到气球b依次给每个气球涂一 ...
- hdu 1556:Color the ball(第二类树状数组 —— 区间更新,点求和)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU 1556 线段树或树状数组,插段求点
1.HDU 1556 Color the ball 区间更新,单点查询 2.题意:n个气球,每次给(a,b)区间的气球涂一次色,问最后每个气球各涂了几次. (1)树状数组 总结:树状数组是一个查 ...
- hdu 1556:Color the ball(线段树,区间更新,经典题)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- HDU.1556 Color the ball (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- HDU 1166 敌兵布阵 (数状数组,或线段树)
题意:... 析:可以直接用数状数组进行模拟,也可以用线段树. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000&quo ...
随机推荐
- 能够在Linux系统中运行的5款大型耐玩游戏
Linux 可能不会很快成为游戏玩家选择的平台 —— Valve Steam Machines 的失败似乎是对这一点的深刻提醒 —— 但这并不意味着该平台没有稳定增长,并且拥有相当多的优秀游戏. 从独 ...
- HttpWebRequest: Remote server returns error 503 Server Unavailable
I have a client server application written in C# .Net 2.0. I have had the client/server response/r ...
- 【Python】torrentParser1.00
代码: #------------------------------------------------------------------------------------ # torrentP ...
- springboot微信sdk方式进行微信支付
https://blog.csdn.net/xsg6509/article/details/80342744
- SpringBoot 启动错误搜集
Spring Boot:The Bean Validation API is on the classpath but no implementation could be found https:/ ...
- android中RecyclerView控件实现点击事件
RecyclerView控件实现点击事件跟ListView控件不同,并没有提供类似setOnItemClickListener()这样的注册监听器方法,而是需要自己给子项具体的注册点击事件. 本文的例 ...
- XAML中特殊符号书写
XAML中特殊符号书写 表示换行. 表示空格.
- Windows下的Qt Creator的安装
采用Qt和Qt creator分别下载和安装的方式:(需要手动设置关联Qt和Qt Creator) 一.软件下载 从http://qt-project.org/downloads分别下载Qt和Qt ...
- MySQL排序:SELECT ORDER BY
SELECT 和ORDER BY结合进行排序: products表例如以下: a 按产品名称列进行排序: b 按多个列进行排序,默认排序顺序为升序: c 指定排序方向,即指定为降序: d 对多个列进行 ...
- python 3使用binascii方法的报错解决
环境是python 3 问题: 使用binascii方法一直出现报错TypeError: a bytes-like object is required, not 'str' #coding: utf ...