HDU 1556 Color the ball
2015-07-12 00:34
447 查看
You can solve it by tree array;
The portal:http://acm.hdu.edu.cn/showproblem.php?pid=1556
The portal:http://acm.hdu.edu.cn/showproblem.php?pid=1556
#include <cstdio> #include <cstdlib> #include <cstring> #include <cmath> #include <iostream> #include <algorithm> using namespace std; const int M = 100005; int Bit[M << 1] ; void Insert(int x,int value) { for(int i = x ; i < M ; i += i & (-i)) { Bit[i] += value; } } int Query(int x){ int ret = 0; for(int i = x ; i ; i -= i & (-i)) { ret += Bit[i]; } return ret; } void Deal_with(){ int n,Left,Right; while(scanf("%d",&n),n) { memset(Bit,0,sizeof(Bit)); for(int i = 0 ; i < n ; i ++ ) { scanf("%d %d",&Left,&Right); Insert(Left,1); Insert(Right+1,-1); } for(int i = 1 ; i <= n ;i ++){ printf("%d",Query(i)); printf(i == n ? "\n" : " "); } } } int main(void){ //freopen("a.in","r",stdin); Deal_with(); return 0; }
相关文章推荐
- Linux之GCC经典入门教程
- 2015071103 - 忘记带火车票
- 交换排序详解(转)
- Linux定时shell脚本
- genymotion的安装及使用
- Could not load file or assembly 'Microsoft.SqlServer.Management.Sdk.Sfc, Version=11.0.0.0, Culture=n
- 2015071102 - 目标
- 浅析 Linux 初始化 init 系统,第 1 部分: sysvinit(转)
- CentOS手动安装sbt过程
- 2015071101 - 爬盘山
- 浅析 Linux 初始化 init 系统,第 2 部分: UpStart(转)
- MySQL的调优
- 【Window Service】关于Window Service的两三事
- IbatisNet配置文件
- HDU 4418 Time travel (高斯消元求期望) 好题
- 浅析 Linux 初始化 init 系统,第 3 部分: Systemd(转)
- 如何终止java线程
- hibernate的hql查询语句总结
- S2.3S3.2H4.3
- EditText的imeOptions