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 ...
随机推荐
- Git-SSH
终端命令: 1.查看ssh ls -al ~/.ssh 存在则会列出对应的 rsa 2.不存在则生成 ssh-keygem -o -t rsa -C "邮箱" -b 4096 3. ...
- Xadmin使用二
1:修改site-title和site-footer,增加菜单折叠效果 在adminx.py中增加下面代码: class GlobalSetting(object): # 设置Title site_t ...
- BZOj1261: [SCOI2006]zh_tree(dp)
Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 400 Solved: 272[Submit][Status][Discuss] Descriptio ...
- springboot整合swagger笔记
首先,在pom.xml中添加依赖 <!--swagger--> <dependency> <groupId>io.springfox</groupId> ...
- 来自一枚初生牛犊不怕虎的小菜鸟的Mock.js使用,不足之处欢迎读者的指出 谢谢
本文章写的是基于require的mock.js的几种常用生成随机数据和ajax模拟前后端的交互信息 <script src="./app/libs/require.js"&g ...
- vue服务端渲染提取css
vue服务端渲染,提取css单独打包的好处就不说了,在这里主要说的是抽取css的方法 要从 *.vue 文件中提取 CSS,可以使用 vue-loader 的 extractCSS 选项(需要 vue ...
- JS高级. 04 增删改查面向对象版歌曲管理、递归、
增 数组.push() 删 数组.splice(开始删除索引,删除几个) 在当前对象中调用当前对象的方法中和属性,必须用this调用 nodeType判断节点类型 节点.nodeType == 1: ...
- Linux之MariaDB
MariaDB数据库的起源 MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可.开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜 ...
- linux wdcp3 上传大文件 服务器i/o错误
在一次上传大文件时 提示 服务器i/o错误 找了些方法都没有解决 最后发现 wdcp3 面板 默认安装时 web服务器引擎是 nginx + apache 共用 而且 nginx 默认并没与安装 ...
- python面向对象-cs游戏示例
#!/usr/local/bin/python3 # -*- coding:utf-8 -*- class Role(object): n = 123 # 类变量 name = "我是类na ...