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: % ...
随机推荐
- yarn快速使用及实践建议
什么是 yarn? 简单来说,yarn 是一个与 npm 功能相同的工具,用于前端项目的依赖管理.在使用 npm 的项目中,使用 npm 命令的地方都可以使用 yran 来代替. 为什么要使用 yar ...
- 2017BAPC初赛A(思维,无序图,向量)
#include<bits/stdc++.h>using namespace std;string goods,sister[100010];int x,m;unordered_map&l ...
- CodeForces 116B【二分匹配】
思路: 暴力..我不会呀.. YY一个二分匹配嘛,然后数组开小了.GG for an hour. #include <bits/stdc++.h> using namespace std; ...
- servlet之doPost()、doGet()
1.doGet和doPost方法的具体应用?即在什么时候程序调用doGet方法,什么时候程序执行doPost方法? HttpServlet是从GenericServlet继承而来,因此HttpServ ...
- 问题:Tomcat启动产生错误严重: Error initializing endpoint java.lang.Exception
1问题描述: Tomcat启动产生错误严重: Error initializing endpoint java.lang.Exception: Socket bind failed: [730048] ...
- react native 安卓生产包无法获取线上数据
android:usesCleartextTraffic="true"
- jenkins相关下载链接
Jenkins官网:https://jenkins.io/ 下载rpm安装包: https://pkg.jenkins.io http://mirrors.jenkins-ci.org/s ...
- idea中使用Git对项目进行版本控制
- STP-17-对抗单向链路问题
单向链路问题是指链路上的两条传输路径中,有一条出现了问题,但并不是两条同时出现问题.这可能是因为线缆错误.切断了一条光纤线缆.拔掉了一根管线.GBIC问题,或其他问题.因为STP会监控入向BPDU,以 ...
- python_魔法方法(二):算术运算
python2.2之后,对类和类型做了同意,将int().float().str().list().touple()这些BIF转换为工厂函数 >>> type(len) <cl ...