HDU 4325 Flowers(树状数组+离散化)
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(树状数组+离散化)的更多相关文章
- 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 ...
- [HDOJ4325]Flowers(树状数组 离散化)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4325 关于离散化的简介:http://blog.csdn.net/gokou_ruri/article ...
- HDU 2227 Find the nondecreasing subsequences (DP+树状数组+离散化)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2227 Find the nondecreasing subsequences ...
- HDU 5256 - 序列变换 ,树状数组+离散化 ,二分法
Problem Description 我们有一个数列A1,A2...An,你现在要求修改数量最少的元素,使得这个数列严格递增.其中无论是修改前还是修改后,每个元素都必须是整数.请输出最少需要修改多少 ...
- 利用id来进行树状数组,而不是离散化以后的val HDU 4417 离线+树状数组
题目大意:给你一个长度为n的数组,问[L,R]之间<=val的个数 思路:就像标题说的那样就行了.树状数组不一定是离散化以后的区间,而可以是id //看看会不会爆int!数组会不会少了一维! / ...
- HDU 5792 World is Exploding(树状数组+离散化)
http://acm.split.hdu.edu.cn/showproblem.php?pid=5792 题意: 思路: lmin[i]:表示左边比第i个数小的个数. lmax[i]:表示左边比第i个 ...
随机推荐
- 20165215 2017-2018-2 《Java程序设计》第6周学习总结
20165215 2017-2018-2 <Java程序设计>第6周学习总结 教材学习内容总结 chapter8 Java把String类定义为final类,即String类不能有子类 用 ...
- TensorFlow 1.2.0新版本完美支持Python3.6,windows在cmd中输入pip install tensorflow就能下载应用最新tensorflow
TensorFlow 1.2.0新版本完美支持Python3.6,windows在cmd中输入pip install tensorflow就能下载应用最新tensorflow 只需在cmd中输入pip ...
- Autel Maxisys MS908CV Description
The new Autel MaxiSys CV Heavy Duty Diagnostic is built on the powerful MaxiSys 908 platform and pro ...
- JVM 一套卷,助你快速掌握优化法则
一:虚拟机内存图解 JAVA 程序运行与虚拟机之上,运行时需要内存空间.虚拟机执行 JAVA 程序的过程中会把它管理的内存划分为不同的数据区域方便管理. 虚拟机管理内存数据区域划分如下图: 数据区域分 ...
- mongoDB 的介绍
一.常用的网站 MongoDB -- 2009年被发布 MongoDB的官网: www.mongodb.org 可以下载安装包 和 使用文档 MongoDB国内官方网站: www.mo ...
- Caused by: java.net.BindException: Address already in use: bind
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'brandService ...
- 利用crontab定时备份nginx访问日志(也可以说是定时切分日志)
在我们的工作中,肯定会涉及到分析访问日志. 但是如果访问日志都集中存在于一个文件中,那数据量就太大了,并且也不利于我们进行分析. 所以我们需要对访问日志进行按时间切割. 思路: 我们可以利用linux ...
- nginx 启动 + uwsgi + django
https://www.cnblogs.com/chenice/p/6921727.html https://blog.csdn.net/Aaroun/article/details/78218131
- python的zipfile、tarfile模块
zipfile.tarfile的用法 先占个位置,后续再实际操作和补充 参考 https://www.cnblogs.com/MnCu8261/p/5494807.html
- 图片上传插件:webuploader
官网链接:https://github.com/fex-team/webuploader