HDU4325--Flowers--树状数组,离散化
Description
As is known to all, the blooming time and duration varies between different kinds of flowers. Now there is a garden planted full of flowers. The gardener wants to know how many flowers will bloom in the garden in a specific time. But there are too many flowers in the garden, so he wants you to help him.
Input
The first line contains a single integer t (1 <= t <= 10), the number of test cases.
For each case, the first line contains two integer N and M, where N (1 <= N <= 10^5) is the number of flowers, and M (1 <= M <= 10^5) is the query times.
In the next N lines, each line contains two integer S i and T i (1 <= S i <= T i <= 10^9), means i-th flower will be blooming at time [S i, T i].
In the next M lines, each line contains an integer T i, means the time of i-th query.
Output
For each case, output the case number as shown and then print M lines. Each line contains an integer, meaning the number of blooming flowers.
Sample outputs are available for more details.
Sample Input
2
1 1
5 10
4
2 3
1 4
4 8
1
4
6
Sample Output
Case #1:
0
Case #2:
1
2
1
很简单的一道树状数组的改段求点的模版题,基本思想是:tree[]为树状数组,N个元素,tree[i]存放的是i至N被加了多少,
所以,修改[l,r]区间值的操作就变为了,
update(l,1);
update(r+1,-1);
查询某点的操作就变为了查询此点的前缀和
需要注意的是,此题目的数据范围太大,需要进行离散化
1 (关于离散化,会再写一篇博客)
```c++
#include
#include
#include
#include
#include
using namespace std;
const int M=100100;
int tree[M];
int q[M];
int N=0;
map ls;
struct node
{
int le;
int ri;
}a[M];
int lowbits(int x)
{
return x&(-x);
}
void update(int i,int val)
{
for(;i0;i-=lowbits(i)){
sum+=tree[i];
}
return sum;
}
void init()
{
memset(tree,0,sizeof(tree));
ls.clear();
}
int main()
{
freopen("data.in","r",stdin);
int m,n;
int t;
int l,r;
int tem;
int casn=1;
cin>>t;
while(t--){
cout>n>>m;
for(int i=0;i>l>>r;
if(ls.find(l)==ls.end()) ls.insert(make_pair(l,1));
if(ls.find(r)==ls.end()) ls.insert(make_pair(r,1));
a[i].le=l;a[i].ri=r;
}
for(int i=0;i>l;
if(ls.find(l)==ls.end()) ls.insert(make_pair(l,1));
q[i]=l;
}
int i=1;
for(map::iterator ite=ls.begin();ite!=ls.end();ite++){
ite->second=i++;
}
N=i-1;
for(int i=0;i
HDU4325--Flowers--树状数组,离散化的更多相关文章
- HDU 4325 Flowers 树状数组+离散化
Flowers Problem Description As is known to all, the blooming time and duration varies between differ ...
- hdu4605 树状数组+离散化+dfs
Magic Ball Game Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- BZOJ_5055_膜法师_树状数组+离散化
BZOJ_5055_膜法师_树状数组+离散化 Description 在经历过1e9次大型战争后的宇宙中现在还剩下n个完美维度, 现在来自多元宇宙的膜法师,想偷取其中的三个维度为伟大的长者续秒, 显然 ...
- POJ 2299 【树状数组 离散化】
题目链接:POJ 2299 Ultra-QuickSort Description In this problem, you have to analyze a particular sorting ...
- HDU4325 树状数组+离散化
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4325 Flowers Time Limit: 4000/2000 MS (Java/Others) ...
- [HDOJ4325]Flowers(树状数组 离散化)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4325 关于离散化的简介:http://blog.csdn.net/gokou_ruri/article ...
- HDU 4325 Flowers(树状数组+离散化)
http://acm.hdu.edu.cn/showproblem.php?pid=4325 题意:给出n个区间和m个询问,每个询问为一个x,问有多少个区间包含了x. 思路: 因为数据量比较多,所以需 ...
- BZOJ-1227 虔诚的墓主人 树状数组+离散化+组合数学
1227: [SDOI2009]虔诚的墓主人 Time Limit: 5 Sec Memory Limit: 259 MB Submit: 914 Solved: 431 [Submit][Statu ...
- POJ 2299 树状数组+离散化求逆序对
给出一个序列 相邻的两个数可以进行交换 问最少交换多少次可以让他变成递增序列 每个数都是独一无二的 其实就是问冒泡往后 最多多少次 但是按普通冒泡记录次数一定会超时 冒泡记录次数的本质是每个数的逆序数 ...
- Bzoj 1901: Zju2112 Dynamic Rankings 主席树,可持久,树状数组,离散化
1901: Zju2112 Dynamic Rankings Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 6321 Solved: 2628[Su ...
随机推荐
- cmusphinx格式问题
在windows下.lm和.dict同时为ANSI编码,输出正确,否则输出乱码或不输出结果.
- 如何在Excel中少犯二(I)
作者:何明科链接:https://zhuanlan.zhihu.com/p/23472480来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 收到不少建议,要求开知乎Li ...
- C/C++ - <string> 与<string.h>、<cstring>的区别
<string.h><string.h>是C版本的头文件,包含比如strcpy.strcat之类的字符串处理函数. <string><string>是C ...
- Arch安装fcitx输入法
安装fcitx,安装gtk.qt模块. [root@ARCH ~]# pacman -S fcitx-im :: There are 4 members in group fcitx-im: :: R ...
- java读写串口
http://blog.csdn.net/xxyy888/article/details/8946046
- Python 学习笔记5
Life is like a box of chocolate. 今天继续学习Python数据结构. http://www.pythondoc.com/pythontutorial3/datastru ...
- 通过Maven配置测试环境和开发环境连接不同的数据库
通过Maven配置测试环境和开发环境连接不同的数据库 作者及来源: 通灵宝玉 - 博客园 收藏到→_→: 此文来自: 马开东博客 网址:http://www.makaidong.com ...
- dedecms 自定义标签的方法
function lib_demotest(&$ctag,&$refObj) { global $dsql,$envs; //属性处理 $attlist="row|12,ti ...
- linux安装文件命令
tar -zxvf apache-tomcat.tar.gz -C /home/poka 注:安装tar.gz的安装包 设置系统自动启动tomcat 切换到root用户,执行命令 #chkconfig ...
- 《Windows驱动开发技术详解》之派遣函数
驱动程序的主要功能是负责处理I/O请求,其中大部分I/O请求是在派遣函数中处理的.用户模式下所有对驱动程序的I/O请求,全部由操作系统转化为一个叫做IRP的数据结构,不同的IRP数据会被“派遣”到不同 ...