Codeforces 600B Queries about less or equal elements(二分查找)
Description
You are given two arrays of integers a and b. For each element of the second array bj you should find the number of elements in array athat are less than or equal to the value bj.
Input
The first line contains two integers n, m (1 ≤ n, m ≤ 2·105) — the sizes of arrays a and b.
The second line contains n integers — the elements of array a ( - 109 ≤ ai ≤ 109).
The third line contains m integers — the elements of array b ( - 109 ≤ bj ≤ 109).
Output
Print m integers, separated by spaces: the j-th of which is equal to the number of such elements in array a that are less than or equal to the value bj.
Sample Input
5 4
1 3 5 7 9
6 4 2 8
3 2 1 4
5 5
1 2 1 2 5
3 1 4 1 5
4 2 4 2 5
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#define MAX 200100
using namespace std;
int a[MAX],b[MAX];
int c[MAX],d[MAX];
int main()
{
int n,m,j,i;
int s;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<m;i++)
scanf("%d",&b[i]);
sort(a,a+n);
for(i=0;i<m;i++)
{
if(i==m-1)
printf("%d\n",upper_bound(a,a+n,b[i])-a);
else
printf("%d ",upper_bound(a,a+n,b[i])-a);
}
// __int64 Max=-1;
// memset(a,0,sizeof(0));
// memset(b,0,sizeof(b));
// memset(d,0,sizeof(d));
// for(i=1;i<=n;i++)
// {
// scanf("%I64d",&s);
// if(s>0)
// d[s]++;
// a[s]=s;
// Max=max(Max,s);
// }
// for(i=1;i<=m;i++)
// {
// scanf("%I64d",&s);
// b[i]=s;
// }
// for(i=1;i<=Max;i++)
// {
// if(a[i]==0)
// a[i]=i+1;
// }
// sort(a,a+n);
// memset(c,0,sizeof(c));
// for(i=1;i<=Max;i++)
// {
// if(a[i]<=i)
// c[i]+=(c[i-1]+d[i]);
// else
// c[i]=c[i-1];
// }
// for(i=1;i<m;i++)
// printf("%I64d ",c[b[i]]);
// printf("%I64d\n",c[b[m]]);
}
return 0;
}
Codeforces 600B Queries about less or equal elements(二分查找)的更多相关文章
- CF 600B Queries about less or equal elements --- 二分查找
CF 600B 题目大意:给定n,m,数组a(n个数),数组b(m个数),对每一个数组b中的元素,求数组a中小于等于数组该元素的个数. 解题思路:对数组a进行排序,然后对每一个元素b[i],在数组a中 ...
- CodeForces - 600B Queries about less or equal elements (二分查找 利用stl)
传送门: http://codeforces.com/problemset/problem/600/B Queries about less or equal elements time limit ...
- Educational Codeforces Round 2 B. Queries about less or equal elements 水题
B. Queries about less or equal elements Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforc ...
- Educational Codeforces Round 2_B. Queries about less or equal elements
B. Queries about less or equal elements time limit per test 2 seconds memory limit per test 256 mega ...
- Queries about less or equal elements CodeForces - 600B(二分)
You are given two arrays of integers a and b. For each element of the second arraybj you should find ...
- Educational Codeforces Round 2 B. Queries about less or equal elements
打开题目连接 题意:给2个数组(无序的)啊a,b,判断b数组中的每一个元素大于a数组中个数. ACcode: #include <iostream> #include <vector ...
- codeforces:MEX Queries分析和实现
首先说明一下MEX,设S是自然数集合N的一个子集,那么S的MEX则为min(N\S),即不包含于S的最小自然数. 题目大意是存在一个空集S,提供n组输入(n<10^5),每组输入对应下面的一个指 ...
- Codeforces Round #768 (Div. 2) D. Range and Partition // 思维 + 贪心 + 二分查找
The link to problem:Problem - D - Codeforces D. Range and Partition time limit per test: 2 second ...
- Codeforces 475D 题解(二分查找+ST表)
题面: 传送门:http://codeforces.com/problemset/problem/475/D Given a sequence of integers a1, -, an and q ...
随机推荐
- tomcat web.xml 配置
1<web-app> 2<error-page> 3<error-code>404</error-code> 4<location>/Not ...
- bzoj1221: [HNOI2001] 软件开发
挖坑.我的那种建图方式应该也是合理的.然后连样例都过不了.果断意识到应该为神奇建图法... #include<cstdio> #include<cstring> #includ ...
- UVa 11054 Wine trading in Gergovia【贪心】
题意:给出n个等距离的村庄,每个村庄要么买酒,要么卖酒,买酒和卖酒的总量相等, 把k个单位的酒从一个村庄运送到相邻的村庄,需要耗费k个单位劳动力,问怎样运送酒使得耗费的劳动力最少 买 卖 ...
- ViewPager+Fragment替代TabHost效果的简单示例
本示例旨在展示fragment替代tabhost的效果,具体的业务逻辑还要根据这个示例进行扩展. 效果图如下: 主Activity代码: package com.llb.view; import ja ...
- delphi 转换sql server 中的 bit类型
FieldByName('e').AsBoolean = false 其中e为 sql server 中的bit类型.
- Autofac 依赖注入 ASP.NET MVC5 插件机制中插件的简单实现
一.前言 由于项目业务复杂,创建了多个插件并把他们放在了不同的项目中,项目使用AutoFac做的IOC:但是主项目可以注入,插件注入失败, 没有为该对象定义无参数的构造函数.下面就一步一步注入插件项目 ...
- Android应用程序版本号管理(官方文档中文版)
在应用程序的 升级/维护 策略中, 版本是一个关键的组成部分. 用户需要了解在他们的设备上所安装的应用程序的版本的特定信息, 以及已安装程序的升级版本可用的情况. 其他应用程序 - 作为同一个套件中发 ...
- android模块化app开发笔记-2插件间布局文件共享
android编程时布局文件,图片资源等都是放在同一个文件夹下,这样照成一个问题就是我们想重用UI布局文件和图片时就还需要其分离这些资料,相信大部分android程序员都遇到过这样的问题,其痛苦程度不 ...
- (原创)LAMP教程3-下载centos6.4
(原创)LAMP教程3-下载centos6.4 今天我要给大家讲的是安装CentOS-6.4-x86_64,是的没有错,就是64位的,因为我的机子是4G的内存,安装64位的centos是绰绰有余啊,但 ...
- (原创)LAMP教程1-下载虚拟机软件
(原创)LAMP教程1 从今天开始会在我的博客更新LAMP教程,第一章节就是安装虚拟机,因为不可能所有的人都有机会操作服务器,所以今天我打算教大家用虚拟机安装配置当下比较流行的框架,lamp. 好了费 ...