hdu-1556 Color the ball---树状数组+区间修改单点查询
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=1556
题目大意:
当N = 0,输入结束。
#include<iostream>
#include<algorithm>
#include<set>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn = + ;
typedef long long ll;
int tree[maxn];
int n;
int lowbit(int x)
{
return x & (-x);
}
//求第x个数字
int sum(int x)
{
int ret = ;
while(x <= n)
{
ret += tree[x];
x += lowbit(x);
}
return ret;
}
//在区间[1, x]加上d
void add(int x, int d)
{
while(x > )
{
tree[x] += d;
x -= lowbit(x);
}
}
int main()
{
while(scanf("%d", &n) && n)
{
int x, y;
memset(tree, , sizeof(tree));
for(int i = ; i <= n; i++)
{
scanf("%d%d", &x, &y);
add(y, );
add(x - , -);
}
for(int i = ; i <= n; i++)
{
int x = sum(i);
printf("%d", x);
if(i == n)printf("\n");
else printf(" ");
}
}
return ;
}
hdu-1556 Color the ball---树状数组+区间修改单点查询的更多相关文章
- HDU 1556 Color the ball (树状数组区间更新)
水题,练习一下树状数组实现区间更新. 对于每个区间,区间左端点+1,右端点的后一位-1,查询每个位置的覆盖次数 #include <cstdio> #include <cstring ...
- 【树状数组区间修改单点查询+分组】HDU 4267 A Simple Problem with Integers
http://acm.hdu.edu.cn/showproblem.php?pid=4267 [思路] 树状数组的区间修改:在区间[a, b]内更新+x就在a的位置+x. 然后在b+1的位置-x 树状 ...
- HDOJ/HDU 1556 Color the ball(树状数组)
Problem Description N个气球排成一排,从左到右依次编号为1,2,3-.N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"牌电动车从 ...
- 【树状数组区间修改单点查询】HDU 4031 Attack
http://acm.hdu.edu.cn/showproblem.php?pid=4031 [题意] 有一个长为n的长城,进行q次操作,d为防护罩的冷却时间,Attack表示区间a-b的墙将在1秒后 ...
- POJ2155 Matrix(二维树状数组||区间修改单点查询)
Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the i-th row an ...
- HDU 1556 Color the ball 树状数组 题解
Problem Description N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的"小飞鸽"牌电动 ...
- 【poj2155】Matrix(二维树状数组区间更新+单点查询)
Description Given an N*N matrix A, whose elements are either 0 or 1. A[i, j] means the number in the ...
- HDU 4031 Attack(线段树/树状数组区间更新单点查询+暴力)
Attack Time Limit: 5000/3000 MS (Java/Others) Memory Limit: 65768/65768 K (Java/Others) Total Sub ...
- NBOJv2 1050 Just Go(线段树/树状数组区间更新单点查询)
Problem 1050: Just Go Time Limits: 3000 MS Memory Limits: 65536 KB 64-bit interger IO format: % ...
随机推荐
- java模拟简易按键精灵
很多小伙伴们都有过抢课的经历,有时候抢不到自己想上的课,只能盼望有人退选,可是很多时候别人退选了,但是很快又被别人抢走了,我们不可能时刻盯着电脑, 这时候如果有一个抢课的程序岂不是很棒.. 出于这个目 ...
- uva 1608 不无聊的序列
uva 1608 不无聊的序列 紫书上有这样一道题: 如果一个序列的任意连续子序列中都至少有一个只出现一次的元素,则称这个序列时不无聊的.输入一个n个元素的序列,判断它是不是无聊的序列.n<=2 ...
- 批处理打开和关闭oracle11g 服务
也许我们经常会有这样一些困惑,如果让oracle随开机启动,我们得电脑内存会被占用殆尽,运行速度会变的异常慢,但是,手动一个一个去启动和关闭,又会非常麻烦.为了解决这个问题,我们有一个办法,那就是写两 ...
- AT2402 Dam
传送门 考虑到一个很显然的事实:水是逃不掉的,一定要接的 所以我们就可以得到一个结论:如果当前的水温比上次低,就混合起来(因为水是逃不掉的),如果高就保留(因为我可以将前面的全部抛弃,只取这个高的) ...
- LeetCode初级算法(数组)解答
这里记录了LeetCode初级算法中数组的一些题目: 加一 本来想先转成整数,加1后再转回去:耽美想到测试的例子考虑到了这个方法的笨重,所以int类型超了最大范围65536,导致程序出错. class ...
- 7、kvm迁移操作
虚拟机迁移要确保虚拟机是关机状态. virsh shutdown privi-server virsh dumpxml privi-server > /etc/libvirt/qemu/priv ...
- 默认约束 default
default :初始值设置,插入记录时,如果没有明确为字段赋值,则自动赋予默认值. 例子:create table tb6( id int primary key auto_increment ...
- jquery 更新值。。vue 如何监听?
size.val(5); // 改变值 //触发 input 事件 ie11 下不能用 size[0].dispatchEvent(new Event('input')); 有些浏览器 不支持.. ...
- Collections.copy
List<String> names = Arrays.asList(new String[nameList.size()]); Collections.copy(names, nameL ...
- 解决spark-shell输出日志信息过多
import org.apache.log4j.Logger import org.apache.log4j.Level Logger.getLogger("org").setLe ...