hdu 1556 A - Color the ball 数状数组做法
#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 数状数组做法的更多相关文章
- 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 ...
- Color the ball(树状数组+线段树+二分)
Color the ball Time Limit : 9000/3000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Tota ...
- 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 c[maxn]; int n; int main() { ) { cin>> ...
- HDU 1166 敌兵布阵 (数状数组,或线段树)
题意:... 析:可以直接用数状数组进行模拟,也可以用线段树. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000&quo ...
- hdu 5869 区间不同GCD个数(树状数组)
Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K ( ...
- poj 2481 Cows(数状数组 或 线段树)
题意:对于两个区间,[si,ei] 和 [sj,ej],若 si <= sj and ei >= ej and ei - si > ej - sj 则说明区间 [si,ei] 比 [ ...
- hdu 6203 ping ping ping(LCA+树状数组)
hdu 6203 ping ping ping(LCA+树状数组) 题意:给一棵树,有m条路径,问至少删除多少个点使得这些路径都不连通 \(1 <= n <= 1e4\) \(1 < ...
随机推荐
- unity中实现三个Logo图片进行若隐若现的切换并有延时切换图片的效果
public GameObject canvas; private Transform logoParent; private Transform Logo_logo; //logo一 private ...
- js小游戏:五子棋
使用纯js的小游戏,五子棋 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> ...
- [POJ2985]The k-th Largest Group
Problem 刚开始,每个数一个块. 有两个操作:0 x y 合并x,y所在的块 1 x 查询第x大的块 Solution 用并查集合并时,把原来的大小删去,加上两个块的大小和. Notice 非旋 ...
- Git的基本使用(github)
关于Git的基本使用: 上传本地文件到github仓库中 首先要有自己的github账号,新建仓库: saiku-3.9 其次 本地安装好 git , 在本地任意目录下新建目录 saiku-3.9, ...
- bluemix部署(一)简单测试,搭建样本flask程序。
1.注册bluemix 这个略 2.登录bluemix 这个也略 3.创建组织 这个确实是和我们的思想不一样.要创建组织.为什么呢?国内的很多服务都没见过组织这个概念.貌似神符合一个中国人是条龙,十个 ...
- Java 算法(背包,队列和栈)
Dijkstra的双栈算术表达式求值算法: import java.util.*; public class Main { public static double evaluate(String a ...
- word-wrap与break-word属性的区别
共同点 word-wrap:break-word与word-break:break-all都能把长单词强行断句 不同点 word-wrap:break-word会首先起一个新行来放置长单词,新的行还是 ...
- MicroOrm.Dapper.Repositories 的使用
https://github.com/geffzhang/MicroOrm.Dapper.Repositories 1.特性标记都是要引用: System.ComponentModel.DataAnn ...
- 8.2 C++标准输出流对象
参考:http://www.weixueyuan.net/view/6408.html 总结: iostream头文件,包含了该头文件后,我们就可以直接使用这些对象,包含标准的输出流对象cout.ce ...
- ubuntu 16.04 菜单栏中无网络链接的图标 无法上网 网络管理版本不兼容
1 卸载network-manager 卸载后将不能联网 sudo apt-get remove network-manager 2 重新安装network-manager重启 引导界面选择ubunt ...