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 ...
随机推荐
- 用VS2015创建ASP.NET Web Forms 应用程序
在 Visual Studio 2015 中,按着以下步骤创建一个 Web Forms 应用程序项目: 1.起始页/文件--->新建项目--->已安装--->模板--->Vis ...
- tp5数据库操作 Db类
一.链接数据库 1.配置文件定义 application\database.php 注意:数据表前缀更改,在文件的prefix选项 2.类定义 二.数据库的基本使用 namespace app\de ...
- mysql学习 1
1.数据库(Database)是按照数据结构来组织.存储和管理数据的仓库 2.RDBMS即关系数据库管理系统(Relational Database Management System)的特点: 1) ...
- 五年磨一剑:Java 开源博客 Solo 1.0.0 发布了!
从 Solo 第一个版本发布至今,已经过去 5 年了.今天我们非常自豪地宣布,Solo 1.0.0 正式发布,感谢一直以来关注 B3log 开源的朋友! 目前 B3log 开源有三款产品: GitHu ...
- Python 之 入门须知
1.Python2.0不支持中文,3.0支持 2.版本问题
- CentOS 7.1 下载,安装,配置
CentOS(全称 Community Enterprise Operating System)是 RHEL 源代码再编译的产物. 2014年初,CentOS 宣布加入 Red Hat. CentOS ...
- javascript: 基于原型的面向对象编程
Douglas Crockford指出javascript是世界上最被误解的编程语言.由于javascript缺少常见的面向对象概念,许多程序猿认为javascript不是一个合适的语言.我在做第一个 ...
- Kendo UI grid 表格数据更新
1.整行数据更新 //获取grid表格var table0 = $(updateTableID).data("kendoGrid");//删除第一条 var lastTableDa ...
- luogu 自适应Simpson1
自适应simpson1 题意 求一个定积分 (可以手推公式,但是我不想推怎么办) 解法 用一个又一个的二次函数覆盖原函数,则可以近似的得到原函数的积分.(这就是Simpson) 模板在下面: #inc ...
- LAMP 环境搭建备忘 -- Linux的安装(一)
LAMP指的是 Linux + Apatch + MySQL / MariaDB + PHP/Perl/Python 一套搭建网站服务器的开源软件组合.工作原理图如下: 下面开始环境搭建 1 Linu ...