http://acm.hdu.edu.cn/showproblem.php?pid=4325

题意:
给出n个区间和m个询问,每个询问为一个x,问有多少个区间包含了x。

思路:

因为数据量比较多,所以需要离散化。区间的离散化需要注意一下,如果端点不连续的话,需要额外插点。

区间情况就用树状数组来维护。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = *1e5+; int n, m, tot;
int a[maxn+],c[maxn]; struct node
{
int l,r;
}query[maxn/]; int lowbit(int x)
{
return x&-x;
} int sum(int x)
{
int ret = ;
while(x>)
{
ret+=c[x];
x-=lowbit(x);
}
return ret;
} void add(int x, int d)
{
while(x<=maxn)
{
c[x]+=d;
x+=lowbit(x);
}
} int main()
{
//freopen("in.txt","r",stdin);
int T;
int kase = ;
scanf("%d",&T);
while(T--)
{
tot = ;
memset(c,,sizeof(c));
scanf("%d%d",&n,&m);
for(int i=;i<=n;i++)
{
scanf("%d%d",&query[i].l,&query[i].r);
a[tot++] = query[i].l;
a[tot++] = query[i].r;
}
a[tot++] = ;
sort(a,a+tot);
int tmp = tot;
for(int i=;i<tmp;i++)
if(a[i]-a[i-]>) a[tot++] = a[i]-;
sort(a,a+tot);
int num = unique(a,a+tot)-a;
for(int i=;i<=n;i++)
{
int l = lower_bound(a,a+num,query[i].l)-a;
int r = lower_bound(a,a+num,query[i].r)-a;
add(l,);
add(r+,-);
}
printf("Case #%d:\n",++kase);
while(m--)
{
int x; scanf("%d",&x);
x = lower_bound(a,a+num,x)-a;
printf("%d\n",sum(x));
}
}
return ;
}

HDU 4325 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. [HDOJ4325]Flowers(树状数组 离散化)

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

  6. HDU 2227 Find the nondecreasing subsequences (DP+树状数组+离散化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2227 Find the nondecreasing subsequences             ...

  7. HDU 5256 - 序列变换 ,树状数组+离散化 ,二分法

    Problem Description 我们有一个数列A1,A2...An,你现在要求修改数量最少的元素,使得这个数列严格递增.其中无论是修改前还是修改后,每个元素都必须是整数.请输出最少需要修改多少 ...

  8. 利用id来进行树状数组,而不是离散化以后的val HDU 4417 离线+树状数组

    题目大意:给你一个长度为n的数组,问[L,R]之间<=val的个数 思路:就像标题说的那样就行了.树状数组不一定是离散化以后的区间,而可以是id //看看会不会爆int!数组会不会少了一维! / ...

  9. HDU 5792 World is Exploding(树状数组+离散化)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=5792 题意: 思路: lmin[i]:表示左边比第i个数小的个数. lmax[i]:表示左边比第i个 ...

随机推荐

  1. 开源数据流管道-Luigi vs Azkaban vs Oozie vs Airflow

    原文链接:https://www.jianshu.com/p/4ae1faea733b 随着企业的发展,他们的工作流程变得更加复杂,越来越多的有着错综复杂依赖关系的工作流需要增加监控,故障排除.如果没 ...

  2. android studio 添加get,set方法快捷方式

    android studio 添加get,set方法快捷方式

  3. eclipse 依赖别的 工程 断点进不去

    maven Debug 发现进不了断点. 点击右键-->Properties-->Java Compiler-->Classfile Generation, 勾选上Add line  ...

  4. GoldenGate 12.3微服务架构与传统架构的区别

    随着Oracle GoldenGate 12c(12.3.0.1.0)的发布,引入了可用于复制业务数据的新架构. 多年来,这种架构有着不同的称谓,Oracle终于在最后GA发布的版本中,以“Micro ...

  5. The Little Prince-12/13

    The Little Prince-12/13 突然发现:这应该是一封情书~ 我那时什么也不懂!我应该根据她的行为,而不是根据她的话来判断她. 她使我的生活芬芳多彩,我真不该离开她跑出来.我本应该猜出 ...

  6. ubunta apt install error

    ubuntu系统: 用apt-get命令安装一些软件包时,总报错:E:could not get lock /var/lib/dpkg/lock -open等 出现这个问题的原因可能是有另外一个程序正 ...

  7. 理解Sql Server 事务隔离层级(Transaction Isolation Level)

    关于Sql Server 事务隔离级别,百度百科是这样描述的 隔离级别:一个事务必须与由其他事务进行的资源或数据更改相隔离的程度.隔离级别从允许的并发副作用(例如,脏读或虚拟读取)的角度进行描述. 隔 ...

  8. hiho一下 第144周

    题目1 : 机会渺茫 时间限制:5000ms 单点时限:1000ms 内存限制:256MB 描述 小Hi最近在追求一名学数学的女生小Z.小Z其实是想拒绝他的,但是找不到好的说辞,于是提出了这样的要求: ...

  9. 从2D图片生成3D模型(3D-GAN)

    https://blog.csdn.net/u014365862/article/details/54783209 3D-GAN是使用生成对抗网络学习2D图像到3D模型的映射,生成网络负责生成3D模型 ...

  10. jQuery中prop和attr区别

    问题 今天给一个button加onclick事件,由于最后button根据需要转成字符串,因此不能使用jQurey.click(),只能给button添加onclick属性的方式. 于是,$butto ...