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 ...
随机推荐
- MongoDB的文档、集合、数据库(二)
为了理解MongoDB的名词,可以将其于关系型数据库进行对比: 一.文档 概述 文档是MongoDB的核心概念,是数据的基本单元,非常类似于关系数据库中的行.在MongoDB中,文档表示为键值对的一个 ...
- 如何区分USB 2.0 和USB 3.0插口
USB3.0的速度是USB2.0的十倍,并且比USB2.0更加节能,同时,还能向下兼容USB2.0.那么,我们怎么区分USB2.0 和 USB 3.0呢. 电脑(有USB2.0和USB3.0的插口) ...
- 关于UI设计行业的认识再到认识
相信很多同学和我一样提及到UI行业时,尤其是连门槛都没有踏入半步时,总会一脸茫然. 我也是一样的,我刚接触UI的前半个月,文章读过好多,作品也看过好多,什么"小白入门UI的十大建议啊&quo ...
- Mockplus教程:分分钟搞定APP首页原型设计
Mockplus是一款快速原型设计工具,支持包括APP原型在内的多种原型与线框图设计.除了快速,Mockplus广受欢迎更因为它极低的上手门槛.今天小编就为大家展示如何用Mockplus在3分钟内完成 ...
- Java读properties文件中文乱码问题的解决方法
java读properties文件,包含中文字符的主要有两种: 1.key中包含中文字符的(value中也有可能包含) 2.key中不包含中文字符的(value中有可能包含) 1.key中包含中文字符 ...
- KOBAS
1. What is KOBAS 3.0? KOBAS (KEGG Orthology Based Annotation System) is a web server for gene/protei ...
- ubuntu16下Elasticsearch5.1.1安装部署
本人在安装es5.1.1版本时候整理的一些过程,参照了网上部分过程:其中过程中也出现一些其它问题,出现的问题和解决方案都整理在此文中. 1Elasticsearch5.1.1安装 到ES官网https ...
- Remove duplicates
https://github.com/Premiumlab/Python-for-Algorithms--Data-Structures--and-Interviews/blob/master/Moc ...
- hdu-1133
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1133 思路:有m个人拿50元的纸币,n个人拿100元的纸币门票价格是50元,要求每个售票员遇到100元 ...
- excel如何设置自增序列
见图1 见图2 4,如果内容对您有所帮助,请打赏---1毛就足够感动我,诚信交友~