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 ...
随机推荐
- Flask的集中控制
想通过一个统一的机制,同时允许一些公共的逻辑 {% if args["NoUser"] %} 无用户! {% else %} <!DOCTYPE html PUBLIC &q ...
- MAC高效软件必备-落雨
更新时间:2017年09月19日23:45:29 使用MAC有一年多,最想说的莫过于如何打造一个高效的使用Mac的体验. 1. MAC任务栏管理,窗口切换 1. Mac任务栏管理(类似于Windows ...
- Log4j日志体系结构
转自:https://my.oschina.net/andylucc/blog/794867 摘要 我们在写日志的时候首先要获取logger,在每一个使用log4j的项目都有很多个地方要获取logge ...
- Windows xcopy
1.考虑下面的需求,把aaa目录下面的111.txt 拷贝到 bbb,如下:echo onxcopy .\aaa\111.txt .\bbb\ /ypause2.注意这里表示路径要用右斜杠,因为左斜杠 ...
- 企业防火墙之iptables
1.1 企业中安全优化配置原则 尽可能不给服务器配置外网ip ,可以通过代理转发或者通过防火墙映射.并发不是特别大情况有外网ip,可以开启防火墙服务. 大并发的情况,不能开iptables,影响性能, ...
- 解决input框中加入disabled="disabled"之后,改变字体的颜色(默认的是灰色)
在input框中加入disabled="disabled"之后,字体默认的就变成灰色了 解决方案 input[disabled]{color:#fff;opacity:1} dis ...
- 简单实用的extend对象合并
/** * 合并对象 * 示例:o = extend({ a: 'a' }, o); */ function extend(s, t) { if (!s) { return {}; } if (!s) ...
- hadoop三个配置文件的参数含义说明(转)
来自:http://blog.csdn.net/yangjl38/article/details/7583374 1 获取默认配置 配置hadoop,主要是配置core-site.xml, ...
- sync_binlog
sync_binlogMySQL提供一个sync_binlog参数来控制数据库的binlog刷到磁盘上去.虽然binlog也有binlog cache,但是MySQL并没有控制binlog cache ...
- http协议版本历史
1.http 0.9 2.http 1.0 3. http 1.1 4.http 2.0 推送:主动发送js.css推送到浏览器. 二进制流:可以并行发送数据. 2019.3.18补充: (1)htt ...