HDU 1556 Color the ball【树状数组】
题意:给出n个区间,每次给这个区间里面的数加1,询问单点的值
一维的区间更新,单点查询,还是那篇论文里面讲了的
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cmath>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<algorithm>
using namespace std; typedef long long LL;
const int INF = (<<)-;
const int mod=;
const int maxn=; int n;
int c[maxn]; int lowbit(int x){ return x &(-x);} int sum(int x){
int ret=;
while(x>){
ret+=c[x];x-=lowbit(x);
}
return ret;
} void add(int x,int d){
while(x<=n){
c[x]+=d; x+=lowbit(x);
}
} int main(){
while(scanf("%d",&n) != EOF){
if(n == ) break;
memset(c,,sizeof(c));
for(int i=;i<=n;i++){
int a,b;
scanf("%d %d",&a,&b);
add(a,);add(b+,-);
}
printf("%d",sum());
for(int i=;i <= n;i++)
printf(" %d",sum(i));
printf("\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便为骑上他的"小飞鸽"牌电动 ...
- Color the ball(树状数组+线段树+二分)
Color the ball Time Limit : 9000/3000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Tota ...
- 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: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 5862 Counting Intersections(离散化+树状数组)
HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...
- hdu 5517 Triple(二维树状数组)
Triple Time Limit: 12000/6000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
随机推荐
- Excel导入到DataTable ,DataTable导入到Excel
using System; using System.Collections.Generic; using System.Linq; using System.Text; using NPOI.SS. ...
- 防范CSRF(二)
在防范CSRF(一)中使用的是微软默认的设置.在信息安全中默认的往往是最危险的.因此可以考虑更改cookie中默认的名字. 更改默认操作在Global.asax中的Application_Start使 ...
- dfs___刷题记录
poj 1564 给出一个s,n个数,输出所有的能够得到s的方案 #include<cstdio> #include<cstring> #include<iostream ...
- CF960F Pathwalks_权值线段树_LIS
很不错的一道思维题. Code: #include<cstdio> #include<algorithm> #include<iostream> using nam ...
- 在使用easyui datagrid在tab中遇到的问题
当切换tab时,数据加载了,但是table的宽和高不能不能够初始化. 郁闷了好久解决了这个问题: 在页面加载时和切换tab时,获取当前tab的名字,进行内容的初始化 $('a[name="m ...
- python 多列表对应的位置的值形成一个新的列表
list1 = [1, 2, 3, 4, 5] list2 = ['a','b', 'c', 'd', 'e'] list3 = [1, 2, 3, 4, 5] multi_list = map(li ...
- webpack基础知识点
webpack 是一个现代的 JavaScript 应用程序的模块打包器(module bundler). 入口(Entry) webpack 将创建所有应用程序的依赖关系图表(dependency ...
- jvm 虚拟机参数_栈内存分配
1.参数 -Xss 指定线程最大的栈空间,整个参数也直接决定了函数可调用的最大深度 2.测试代码 private static int count; public static void addCou ...
- ACCESS-入门思维导图
ACCESS-入门思维导图 链接:http://pan.baidu.com/s/1bozYiNt 密码:5tly 如果有错误,请告知我!
- Spring boot 使用@Value注入属性
Spring boot 使用@Value注入属性 学习了:http://blog.csdn.net/hry2015/article/details/72353994 如果启动的时候报错: spring ...