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--树状数组,离散化的更多相关文章

  1. HDU 4325 Flowers 树状数组+离散化

    Flowers Problem Description As is known to all, the blooming time and duration varies between differ ...

  2. hdu4605 树状数组+离散化+dfs

    Magic Ball Game Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  3. BZOJ_5055_膜法师_树状数组+离散化

    BZOJ_5055_膜法师_树状数组+离散化 Description 在经历过1e9次大型战争后的宇宙中现在还剩下n个完美维度, 现在来自多元宇宙的膜法师,想偷取其中的三个维度为伟大的长者续秒, 显然 ...

  4. POJ 2299 【树状数组 离散化】

    题目链接:POJ 2299 Ultra-QuickSort Description In this problem, you have to analyze a particular sorting ...

  5. HDU4325 树状数组+离散化

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4325 Flowers Time Limit: 4000/2000 MS (Java/Others)   ...

  6. [HDOJ4325]Flowers(树状数组 离散化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4325 关于离散化的简介:http://blog.csdn.net/gokou_ruri/article ...

  7. HDU 4325 Flowers(树状数组+离散化)

    http://acm.hdu.edu.cn/showproblem.php?pid=4325 题意:给出n个区间和m个询问,每个询问为一个x,问有多少个区间包含了x. 思路: 因为数据量比较多,所以需 ...

  8. BZOJ-1227 虔诚的墓主人 树状数组+离散化+组合数学

    1227: [SDOI2009]虔诚的墓主人 Time Limit: 5 Sec Memory Limit: 259 MB Submit: 914 Solved: 431 [Submit][Statu ...

  9. POJ 2299 树状数组+离散化求逆序对

    给出一个序列 相邻的两个数可以进行交换 问最少交换多少次可以让他变成递增序列 每个数都是独一无二的 其实就是问冒泡往后 最多多少次 但是按普通冒泡记录次数一定会超时 冒泡记录次数的本质是每个数的逆序数 ...

  10. Bzoj 1901: Zju2112 Dynamic Rankings 主席树,可持久,树状数组,离散化

    1901: Zju2112 Dynamic Rankings Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 6321  Solved: 2628[Su ...

随机推荐

  1. 关于No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active arch=x86_64, VALID_ARCHS=armv7 armv7s)使用百度地图的解决办法

    出现的原因:armv7s是应用在iPhone 5 A6 的架构上的解决的方式:1,在Project target里“Architectures”设置为“Standard (armv7,armv7s)” ...

  2. @+android:id的一些记录

    在修改Settings模块的APN列表时,遇到了类似标题中的一些写法. 在网上查了一下: 加上android:表示引用android.R.id里面定义的id资源,如果android.R.id里面确实有 ...

  3. 如何将编译出来的images拷贝到windows下面刷机

    由于SPRD的刷机工具ResearchDownload运行在window环境下:这样,我们平时在开发环境下编译出来的镜像文件就不能直接用于刷机了. 这里涉及到一个双系统中文件共享的方法.由于企业信息安 ...

  4. E - 小晴天老师系列——我有一个数列!

    E - 小晴天老师系列——我有一个数列! Time Limit: 20000/10000MS (Java/Others)    Memory Limit: 128000/64000KB (Java/O ...

  5. photoshop的页面制作练习2

  6. 如何为CentOS 7配置静态IP地址

    问题:在CentOS 7上,我想要将我其中一个网络接口从DHCP改为静态IP地址配置,如何才能永久为CentOS或RHEL 7上的网络接口分配静态IP地址? 如果你想要为CentOS 7中的某个网络接 ...

  7. jQuery.on() 函数详解[http://www.365mini.com/page/jquery-on.htm]

    中文手册 2014年09月01日 暂无评论 on()函数用于为指定元素的一个或多个事件绑定事件处理函数. 此外,你还可以额外传递给事件处理函数一些所需的数据. 从jQuery 1.7开始,on()函数 ...

  8. oracle11g 卸载和安装(win7,32位)

    完全卸载oracle11g步骤:1. 开始->设置->控制面板->管理工具->服务 停止所有Oracle服务.2. 开始->程序->Oracle - OraDb11 ...

  9. VBS基础篇 - 杂项 - Sendkeys

    VBS基础篇 - 杂项 - Sendkeys   模拟键盘操作,将一个或多个按键指令发送到指定Windows窗口来控制应用程序运行 其使用格式为:object.SendKeys(string) obj ...

  10. 编写一个闹钟和定时关机工具(MFC VS2010)

    这个小工具在自己生活当中能用到,运行软件以后,会显示当前的系统时间,然后你可以设定时间,再选择是定时响铃还是关机.截图如下: 前言:本程序采用visual studio 2010 ,对话框类型的应用程 ...