hdu 1556 Color the ball (区间更新 求某点值)
当N = 0,输入结束。
1 1
2 2
3 3
3
1 1
1 2
1 3
0
3 2 1
#include<bits/stdc++.h> using namespace std;
int lowbit(int x)
{
return x&(-x);
}
int n;
const int N=1e5+;
int s[N];
void updata(int x,int y)
{
for(int i=x;i<=n;i+=lowbit(i)){
s[i]+=y;
}
} int sum(int x)
{
int ans=;
for(int i=x;i>;i-=lowbit(i)){
ans+=s[i];
}
return ans;
}
int main()
{
while(scanf("%d",&n)==,n){
memset(s,,sizeof(s));
for(int i=;i<n;i++){
int a,b;
scanf("%d %d",&a,&b);
updata(a,);
updata(b+,-);
}
for(int i=;i<=n;i++){
if(i!=) printf(" ");
printf("%d",sum(i));
}
printf("\n");
}
return ;
}
hdu 1556 Color the ball (区间更新 求某点值)的更多相关文章
- 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 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 我真的该认真的复习一下以前没懂的知识了,今天看了一下线段树,以前只会用模板,现在看懂了之后,发现还有这么多巧妙的地方,好厉害啊 所以就应该尽量搞懂 弄明白每个知识点 [题 ...
- HDU 1556 Color the ball(线段树:区间更新)
http://acm.hdu.edu.cn/showproblem.php?pid=1556 题意: N个气球,每次[a,b]之间的气球涂一次色,统计每个气球涂色的次数. 思路: 这道题目用树状数组和 ...
- hdu 1556 Color the ball(线段树区间维护+单点求值)
传送门:Color the ball Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/3276 ...
- HDU 1556 Color the ball (一维树状数组,区间更新,单点查询)
中文题,题意就不说了 一开始接触树状数组时,只知道“单点更新,区间求和”的功能,没想到还有“区间更新,单点查询”的作用. 树状数组有两种用途(以一维树状数组举例): 1.单点更新,区间查询(即求和) ...
- HDU 1556 Color the ball (树状数组区间更新)
水题,练习一下树状数组实现区间更新. 对于每个区间,区间左端点+1,右端点的后一位-1,查询每个位置的覆盖次数 #include <cstdio> #include <cstring ...
随机推荐
- hadoop二次排序
import java.io.DataInput; import java.io.DataOutput; import java.io.File; import java.io.IOException ...
- C#实现异步GET的方法
using System; using System.Collections.Generic; using System.Configuration; using System.IO; using S ...
- 浅谈Java 8的新特性和使用场景
一.default方法: 通过default方法,可以在接口(Interface interface_name)中添加实例化方法: 代码如下: public interface TestDef ...
- 从 React 的组件更新谈 Immutable 的应用
在介绍 Immutable 如何在 React 中应用之前,先来谈谈 React 组件是如何更新的. React 是基于状态驱动的开发,可以将一个组件看成是一个有限状态机,组件要更新,必须更新状态. ...
- multimap的使用
multimap由于允许有重复的元素,所以元素插入.删除.查找都与map不同. 插入insert(pair<a,b>(value1,value2)) #include <iostre ...
- 使用zxing二维码识别
1.多二维码识别 (同一张图片中多二维码识别) 直接上代码舒服: pom文件: <!-- QR Code --> <dependency> <groupId>com ...
- 【PHP项目】产品新增的多图上传
产品新增:多图上传 1:html的更改 在 type=file的input框中添加multiple="multiple" name属性中必须添加[] ,否则$_FILES只能接收最 ...
- 在一台Apache服务器上创建多个站点(不同域名)
使用不同的域名来区分不同的网站,所有的域名解析都指向同一个 IP 地址.Apache通过在HTTP头中附带的 host参数来判断用户需要访问哪一个网站. 例如要在一台服务器上设置如下两个站点: htt ...
- Xshell6破解
链接: https://pan.baidu.com/s/1P9kMmGdLfpPPxEgUxNXrhw 提取码: s3js
- 2.3 进程控制之exec函数族
学习目标:学习使用exec函数族的重要的几个函数 一.引言 进程通过exec函数根据指定的文件名或目录名执行另一个可执行文件,当进程调用exec函数时,该进程的数据段.代码段和堆栈段完全被新程序替换 ...