HDU 1556 区间查询
Color the ball
Time Limit: 3000 MS Memory Limit: 32768 KB
64-bit integer IO format: %I64d , %I64u Java class name: Main
Description
Input
当N = 0,输入结束。
Output
Sample Input
3
1 1
2 2
3 3
3
1 1
1 2
1 3
0
Sample Output
1 1 1
3 2 1
#include <iostream>
#include <string.h>
#include <stdio.h> using namespace std;
#define max 100005
int c[max];
int n; int lowbit(int x)
{
return x&-x;
} void update(int i,int val)
{
while(i>)
{
c[i]+=val;
i-=lowbit(i);
}
} int get_sum(int i)
{
int s=;
while(i<=n)
{
s+=c[i]; ///上下两行 不可换位置~~~~~
i+=lowbit(i);
}
return s;
} int main()
{ while(scanf("%d",&n),n)
{
int x,y;
memset(c,,sizeof(c));
for(int i=; i<n; i++)
{ scanf("%d%d",&x,&y);
update(y,);
update(x-,-);
}
for(int i=; i<n; i++) ///注意脚标
printf("%d ",get_sum(i));
printf("%d\n",get_sum(n));
}
return ;
}
HDU 1556 区间查询的更多相关文章
- 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(线段树,区间更新,经典题)
Color the ball Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- 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 (线段树 区间更新 单点查询)
HDU.1556 Color the ball (线段树 区间更新 单点查询) 题意分析 注意一下pushdown 和 pushup 模板类的题还真不能自己套啊,手写一遍才行 代码总览 #includ ...
- hdu 1556 Color the ball 线段树
题目链接:HDU - 1556 N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a <= b),lele便为骑上他的“小飞鸽"牌电动车从气球a开始到气 ...
- hdu 1556.Color the ball 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556 题目意思:有 n 个气球从左到右排成一排,编号依次为1,2,3,...,n.给出 n 对 a, ...
- hdu 1556 Color the ball(树状数组)
链接:http://acm.hdu.edu.cn/showproblem.php?pid=1556 题意:N个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数[a,b]之间的气球 ...
- HDU 1556 Color the ball(线段树:区间更新)
http://acm.hdu.edu.cn/showproblem.php?pid=1556 题意: N个气球,每次[a,b]之间的气球涂一次色,统计每个气球涂色的次数. 思路: 这道题目用树状数组和 ...
随机推荐
- hisat2+stringtie+ballgown
hisat2+stringtie+ballgown Posted on 2016年11月25日 早在去年九月,我就写个博文说 RNA-seq流程需要进化啦!http://www.bio-info-tr ...
- Python-多线程之消费者模式和GIL全局锁
一.生产者和消费者模式 什么是生产者消费者模式 生产者消费者模式是通过一个容器来解决生产者和消费者的强耦合问题.生产者和消费者彼此之间不直接通讯,而通过阻塞队列来进行通讯, 所以生产者生产完数据之后不 ...
- ES6 中 let and const
let 和 const 命令 let 命令 基本用法 ES6 新增了let命令,用来声明变量.它的用法类似于var,但是所声明的变量,只在let命令所在的代码块内有效. { let a = 10; v ...
- 大神的P图过程!快来偷窥!
来自美国的艺术家James(@jameasons) 平时我们总是能看到一些大神合成出这样的图片, 但是他们P图的过程是怎样的,很多人都是不知道的. 接下来再看看这位大神的其他作品, 如果你看了上面视频 ...
- [Robot Framework] Robot Framework里面的变量怎么知道是在哪里定义的?
看变量在哪里定义的:Ctrl+Alt+Space
- mongoDB(Window)
1.启动命令 mongod --dbpath F:\mongo\data 注:dbpath路径不能有空格,我开始用F:\Program Files,就因为有一个空格,失败了. ...
- Roslyn研究随笔
Roslyn概述: http://blogs.ejb.cc/archives/7604/dotnet-compile-platform-roslyn-overview 使用Microsoft Rosl ...
- android c 读写文件
1.包含头文件 #include<unistd.h>#include<sys/types.h>#include<sys/stat.h>#include<fcn ...
- 在ugui上显示3d物体
1.接下来,使Cube的Layer和背景一样为UI层, 2.在将我们的主相机culling Mask改为UI,如果你还想渲染其他层的物体,可以根据需要该为需要的层,或者直接改为Everyting 3. ...
- C# Bitmap长宽参数构造的图片对象的每个像素ARGB都是0
var img = new Bitmap(100 , 100); for (int i = 0; i < img.Width; i++) { for (int j = 0; j < i ...