HDU 1556 Color the ball (数状数组)
Color the ball
Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 5397 Accepted Submission(s): 2882
当N = 0,输入结束。
1 1
2 2
3 3
3
1 1
1 2
1 3
0
3 2 1
#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; const int N=; int n,arr[N],level[N]; int lowbit(int x){
return x&(-x);
} void update(int i,int val){
while(i<=n){
arr[i]+=val;
i+=lowbit(i);
}
} int Sum(int i){
int ans=;
while(i>){
ans+=arr[i];
i-=lowbit(i);
}
return ans;
} int main(){ //freopen("input.txt","r",stdin); while(~scanf("%d",&n) && n){
memset(arr,,sizeof(arr));
memset(level,,sizeof(level));
int a,b;
for(int i=;i<=n;i++){
scanf("%d%d",&a,&b);
update(a,);
update(b+,-); //这两个函数刚好更新x~y之间的值都+1
}
for(int i=;i<n;i++)
printf("%d ",Sum(i));
printf("%d\n",Sum(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便为骑上他的"小飞鸽"牌电动 ...
- hdu 1556 A - Color the ball 数状数组做法
#include<bits/stdc++.h> using namespace std; ; int n; int c[maxn]; int lowbit(int x) { return ...
- 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 线段树或树状数组,插段求点
1.HDU 1556 Color the ball 区间更新,单点查询 2.题意:n个气球,每次给(a,b)区间的气球涂一次色,问最后每个气球各涂了几次. (1)树状数组 总结:树状数组是一个查 ...
- 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 1166 敌兵布阵 (数状数组,或线段树)
题意:... 析:可以直接用数状数组进行模拟,也可以用线段树. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000&quo ...
随机推荐
- RAMPS1.4 3d打印控制板接线与测试1
1.需要下载的软件 1.1 固件上传工具--Arduino IDE 这是上传固件的必备工具,有了这个软件让上传固件变的容易很多,插上USB,就可以轻松上传. 下载地址:windows版本:http:/ ...
- CareerCup Facebook Total number of substring palindrome
Write a function for retrieving the total number of substring palindromes. For example the input is ...
- Google想出了一个决定人员晋升的算法,然后就没有然后了......
Google 有点跑偏了,逗死我了~实践一下也好~ Prasad Setty 是 Google People Analytics 团队的副总裁.7 年前 Google 成立的这支团队的职责是收集和利用 ...
- oracle 对表赋权限
grant select,insert,delete,update on yizhen123.tpp_t_dz_yinglian to wangyd;
- logstash启动脚本
1 nohup ./redis-server 1>log.log 2>error.log & 2 nohup ./elasticsearch -f & 3 nohup ...
- ArcGIS10.6了解一下
因为计算机水平不断更新,ESRI不得不重新倾力打造下一代ArcMap,叫ArcGIS Pro,现在ArcGIS Pro功能有一定地突显,但还不够强大和稳定:而ArcGIS Desktop方面没有什么大 ...
- C# .Net计算函数执行的时间
C#计算函数执行的时间 protected void StopwatchTest() { System.Diagnostics.Stopwatch stopwatch = new System.Dia ...
- vue中的ajax - axios
vue中的ajax - axios axios - 简书 使用 axios 实现 ajax 方案 VUE 更好的 ajax 上传处理 axios.js vue.js 自2.0版本已经不对 vue-re ...
- loadrunner -27778 https连接问题
Error -27778: SSL protocol error when attempting to read with host "×××.*****"
- tcmalloc asan
http://blog.csdn.net/jinzhuojun/article/details/46659155 http://blog.csdn.net/hanlizhong85/article/d ...