Flowers(二分水过。。。)
Flowers
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 2579 Accepted Submission(s): 1265
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.
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.
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.
1 1
5 10
4
2 3
1 4
4 8
1
4
6
0
Case #2:
1
2
1
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int INF=0x3f3f3f3f;
const double PI=acos(-);
#define mem(x,y) memset(x,y,sizeof(x))
const int MAXN=1e5+;
int s[MAXN],e[MAXN];
int main(){
int t,M,N,flot=;
scanf("%d",&t);
while(t--){
scanf("%d%d",&N,&M);
for(int i=;i<N;i++){
scanf("%d%d",&s[i],&e[i]);
}
sort(s,s+N);sort(e,e+N);
int q;
printf("Case #%d:\n",++flot);
// for(int i=0;i<N;i++)printf("%d ",s[i]);puts("");
// for(int i=0;i<N;i++)printf("%d ",e[i]);puts("");
while(M--){
scanf("%d",&q);
int x=upper_bound(s,s+N,q)-s;
int y=lower_bound(e,e+N,q)-e;
//printf("%d %d\n",x,y);
// if(e[y-1]==q)y--;
// if(s[x]==q)x++;
printf("%d\n",x-y);
}
}
return ;
}
Flowers(二分水过。。。)的更多相关文章
- Candies CodeForces - 991C(二分水题)
就是二分暴力就好了 为什么要记下来 呵呵....emm你说为什么... 行吧 好吧 我一直以为我的二分出问题了 原来不是 依旧很帅 统计的时候求的减了多少次 然后用次数乘了mid 这样做会使那个人获 ...
- C - Can you solve this equation? HDU - 2199(二分水题)
Now,given the equation 8x^4 + 7x^3 + 2x^2 + 3x + 6 == Y,can you find its solution between 0 and 100; ...
- Bridging signals(二分 二分+stl dp)
欢迎参加——每周六晚的BestCoder(有米!) Bridging signals Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 6 ...
- Color the ball(树状数组+线段树+二分)
Color the ball Time Limit : 9000/3000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Tota ...
- BZOJ3613 南园满地堆轻絮 二分/贪心
正解:贪心 解题报告: 传送门! 这题似乎是可以二分水过的,,,但数据可以加强一下就能简单把二分卡住了,或者修改下空间限制什么的反正就很容易能卡住 所以这里介绍一个优秀的贪心做法,O(n)的时间复杂度 ...
- pairs
pairs http://acm.hdu.edu.cn/showproblem.php?pid=5178 Time Limit: 2000/1000 MS (Java/Others) Memor ...
- AC日记——[Sdoi2010]粟粟的书架 bzoj 1926
1926 思路: 主席树+二分水题: 代码: #include <bits/stdc++.h> using namespace std; #define maxn 500005 #defi ...
- 牛客网NOIP赛前集训营-提高组18/9/9 A-中位数
链接:https://www.nowcoder.com/acm/contest/172/A来源:牛客网 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 262144K,其他语言5242 ...
- hdu5249
这个是去年astar的题~ 标准做法主席树,然而渣渣并不会(我确实叫zhazha...), 所以,他先离线,离散化,然后树状数组+二分水过了.... 离线的目的主要是为了离散化,剩下的就和用一个树状数 ...
随机推荐
- java.lang.UnsupportedClassVersionError: Bad version number in .class file 解决方案
在Myeclipse中运行小应用程序时出现如下异常的解决办法 java.lang.UnsupportedClassVersionError: Bad version number in .class ...
- Sicily-1156
一. 模仿树的的先序遍历.范围是1000个节点.用数组存储节点的信息. 二. 要注意的是,头结点是不确定的,所以在前序遍历之前要找出头结点,除了头结点的下标值出现一次之外,其他结点 ...
- java线程学习——汉堡销售问题
汉堡店中有一个负责做汉堡的厨师,一个负责销售的营业员,用java线程表示他们的营业过程: 问题原型就是生产者与消费者的问题. 首先定义一个汉堡包箱子类与几个相关的变量类: public class H ...
- 《UNIX环境高级编程》笔记--UNIX标准化及实现
1.UNIX标准化 1.1.ISO C 1989 年后期,C程序设计语言的ANSI(American National Standards Institute) 标准X3. 15 9-1989得到批准 ...
- HA for openstack
mysql ha instance ha openstack博客:http://blog.csdn.net/tantexian/article/list/2 使用eclipse远程调试openstac ...
- 微信网页签名失败(invalid signature)
签名失败,建议按以下步骤排查 确认签名算法正确,可用 http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=jsapisign 页面工具进行校验. 确认con ...
- sql日期转换格式
Select CONVERT(varchar(100), GETDATE(), 0): 05 16 2006 10:57AM Select CONVERT(varchar(100), GETDATE( ...
- C#基础面试
1. 简述Private.Protected.Public.Internal 等访问修饰符的访问权限问题 Private:私有成员,只有类的内部成员可以访问 Protected:保护成员,在类的内部和 ...
- ThinkPHP - 事务操作
/* * 添加酒店和房型 * */ public function insertAll($arr_hotel=array(),$arr_room=array()){ $model = new Mode ...
- SSIS CDC(Change Data Capture)组件在数据库中启用报错。 The error returned was 14234: 'The specified '@server' is invalid
昨天实验CDC,在数据库中执行以下语句的时候出错. EXEC sys.sp_cdc_enable_table @source_schema = N'stg', @source_name = N'CDC ...