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: % ...
随机推荐
- Spark 中的 RPC 的几个类
Spark 中 RPC 部分的涉及了几个类,有点晕,在此记录一下 1. RpcEndpoint: RPC的一个端点.给定了相应消息的触发函数.保证 `onStart`, `receive` and ...
- 洛谷P1092 虫食算
P1092 虫食算 题目描述 所谓虫食算,就是原先的算式中有一部分被虫子啃掉了,需要我们根据剩下的数字来判定被啃掉的字母.来看一个简单的例子: http://paste.ubuntu.com/2544 ...
- nodejs安装及使用步骤详解
就一段小小的时间不用,就忘得差不多了,果然好记性不如乱笔头. 1.必须要安装node环境(建议装在C盘,这是一个系统盘)+安装mongoose数据库 +Robot 3T之于mongodb就相当于so ...
- P1089津津的储蓄计划
题目描述 津津的零花钱一直都是自己管理.每个月的月初妈妈给津津300300元钱,津津会预算这个月的花销,并且总能做到实际花销和预算的相同. 为了让津津学习如何储蓄,妈妈提出,津津可以随时把整百的钱存在 ...
- lifecycle-mapping-metadata.xml
<?xml version="1.0" encoding="UTF-8"?> <lifecycleMappingMetadata> &l ...
- JD孔_20160920
1. 2. 3.
- HDU 5917 Instability ramsey定理
http://acm.hdu.edu.cn/showproblem.php?pid=5917 即世界上任意6个人中,总有3个人相互认识,或互相皆不认识. 所以子集 >= 6的一定是合法的. 然后 ...
- (转)Linux硬链接、软链接及inode详解
inode 文件储存在硬盘上,硬盘的最小存储单位叫做“扇区”(Sector).每个扇区储存512字节(相当于0.5KB). 操作系统读取硬盘的时候,不会一个个扇区地读取,这样效率太低,而是一次性连续读 ...
- 上机练习2 生成计算机ID
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threa ...
- 固定ip地址
IP. 配置文件写数据库文件连接时,之前一直是就写个. ; 毕竟之前就自己本地用.现在需要,写ip地址,但是公司点的ip的都是自动获得的.并且过一段时间还会改变. 所以,需要固定一下啊. 首先cm ...