hdu 4325 Flowers(区间离散化)
http://acm.hdu.edu.cn/showproblem.php?pid=4325
Flowers
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2633 Accepted Submission(s): 1290
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 Si and Ti (1 <= Si <= Ti <= 10^9), means i-th flower will be blooming at time [Si, Ti].
In the next M lines, each line contains an integer Ti, means the time of i-th query.
Sample outputs are available for more details.
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm> using namespace std; typedef long long ll;
const int N = ;
const int INF = 0x3f3f3f3f; int c[ * N], a[N], b[N], used[N], d[N]; int cmp(const void *a, const void *b)
{
return *(int *)a - *(int *)b;
} int main()
{
int t, n, m, f = ;
int p, q, k, e;
scanf("%d", &t);
while(t--)
{
f++;
k = ;
memset(used, , sizeof(used));
scanf("%d%d", &n, &m);
for(int i = ; i < n ; i++)
{
scanf("%d%d", &p, &q);
a[i] = p;
b[i] = q;
c[k++] = p;
c[k++] = p - ;/***///这里为嘛,个人认为是防止查询的数比q要小
c[k++] = q;
c[k++] = q + ;/***/
} qsort(c, k, sizeof(c[]), cmp); k = unique (c, c + k)- c;//去重
int x, y, maxn = -INF;
for(int i = ; i < n ; i++)
{
x = lower_bound(c, c + k, a[i]) - c;
y = lower_bound(c, c + k, b[i]) - c;
used[x]++;
used[y + ]--;
maxn = max(maxn, y + );
} for(int i = ; i < maxn ; i++)
used[i + ] += used[i]; printf("Case #%d:\n", f);
while(m--)
{
scanf("%d", &e);
int s = lower_bound(c, c + k, e) - c; printf("%d\n", used[s]);
}
}
return ;
}
hdu 4325 Flowers(区间离散化)的更多相关文章
- HDU 4325 Flowers(树状数组+离散化)
http://acm.hdu.edu.cn/showproblem.php?pid=4325 题意:给出n个区间和m个询问,每个询问为一个x,问有多少个区间包含了x. 思路: 因为数据量比较多,所以需 ...
- HDU 4325 Flowers 树状数组+离散化
Flowers Problem Description As is known to all, the blooming time and duration varies between differ ...
- HDU 4325 Flowers(树状数组)
Flowers Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Sub ...
- hdoj 4325 Flowers 线段树+离散化
hdoj 4325 Flowers 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4325 思路: 直接线段树,按照花的开放区间的大小建树,要注意虽然 ...
- (线段树 区间运算求点)Flowers -- hdu -- 4325
http://acm.hdu.edu.cn/showproblem.php?pid=4325 Flowers Time Limit: 4000/2000 MS (Java/Others) Mem ...
- hdu 3436 splay树+离散化*
Queue-jumpers Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) To ...
- HDU 5862 Counting Intersections(离散化+树状数组)
HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...
- HDU 5726 GCD 区间GCD=k的个数
GCD Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submis ...
- POJ 2528 Mayor's posters 【区间离散化+线段树区间更新&&查询变形】
任意门:http://poj.org/problem?id=2528 Mayor's posters Time Limit: 1000MS Memory Limit: 65536K Total S ...
随机推荐
- python的错误类型和异常处理
# isinstance() # 判断实例a是否属于类b # issubclass() # 判断类a是否为类b的派生类 # 异常处理 try: pass #Exception是错误类型,能catch到 ...
- session以及分布式服务器session共享
一.session的本质 http协议是无状态的,即你连续访问某个网页100次和访问1次对服务器来说是没有区别对待的,因为它记不住你. 那么,在一些场合,确实需要服务器记住当前用户怎么办?比如用户登录 ...
- mvc EF 从数据库更新实体,添加视图实体时添加不上的问题
视图对象没有一列为非null的,解决办法,在视图中,将某一列排除为null的可能,比如:isnull(te,1),即可.
- Go开发之VScode安装
1.找到官网 https://code.visualstudio.com/ 2根据自己机器环境下载 3.下载vscode地址,macos版本 https://vscode.cdn.azure.cn/s ...
- Java ENUM枚举的用法
DK1.5引入了新的类型——枚举.在 Java 中它虽然算个“小”功能,却给我的开发带来了“大”方便. 用法一:常量 在JDK1.5 之前,我们定义常量都是: publicstaticfianl... ...
- Storm 系列(一)基本概念
Storm 系列(一)基本概念 Apache Storm(http://storm.apache.org/)是由 Twitter 开源的分布式实时计算系统. Storm 可以非常容易并且可靠地处理无限 ...
- 社交类APP原型模板分享——微信
微信是一款社交类的APP应用——聊天软件,支持多人群聊. 交互效果主要有滚动内容界面.选择组件触发按钮状态变化.点击下拉展开列表.点击弹出面板等交互操作. 本原型由国产原型工具-Mockplus制作完 ...
- connect strings sql server
https://www.connectionstrings.com/sql-server/ Server=myServerAddress[,port];Database=myDataBase;User ...
- jQuery DataTables插件分页允许输入页码跳转
背景说明 项目中使用jQuery DataTables插件来实现分页表格,但是默认的分页样式不能输入页码进行跳转,在页数非常多的时候使用很不方便,最主要的还是没有达到产品部门的设计要求,所以我需要寻找 ...
- python nan 变成0
在使用numpy数组的过程中时常会出现nan或者inf的元素,可能会造成数值计算时的一些错误.这里提供一个numpy库函数的用法,使nan和inf能够最简单地转换成相应的数值. numpy.nan_t ...