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

Input
5 4
1 3 5 7 9
6 4 2 8
Output
3 2 1 4
Input
5 5
1 2 1 2 5
3 1 4 1 5
Output
4 2 4 2 5
 题意:找出a数组中比b数组中每个数小或者相等的数的个数
题解:c++中的upper_bound(a,a+n,k)返回的就是第一个大于k的位置指针(a按照升序排列)如果a按照降序排列则是第一个小于k的位置指针
       lower_bound(a,a+n,k)返回的就是第一个大于等于k的位置指针(a按照升序排列)如果a按照降序排列则是第一个小于等于k的位置指针
 
#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(二分查找)的更多相关文章

  1. CF 600B Queries about less or equal elements --- 二分查找

    CF 600B 题目大意:给定n,m,数组a(n个数),数组b(m个数),对每一个数组b中的元素,求数组a中小于等于数组该元素的个数. 解题思路:对数组a进行排序,然后对每一个元素b[i],在数组a中 ...

  2. CodeForces - 600B Queries about less or equal elements (二分查找 利用stl)

    传送门: http://codeforces.com/problemset/problem/600/B Queries about less or equal elements time limit ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. Educational Codeforces Round 2 B. Queries about less or equal elements

    打开题目连接 题意:给2个数组(无序的)啊a,b,判断b数组中的每一个元素大于a数组中个数. ACcode: #include <iostream> #include <vector ...

  7. codeforces:MEX Queries分析和实现

    首先说明一下MEX,设S是自然数集合N的一个子集,那么S的MEX则为min(N\S),即不包含于S的最小自然数. 题目大意是存在一个空集S,提供n组输入(n<10^5),每组输入对应下面的一个指 ...

  8. 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 ...

  9. Codeforces 475D 题解(二分查找+ST表)

    题面: 传送门:http://codeforces.com/problemset/problem/475/D Given a sequence of integers a1, -, an and q ...

随机推荐

  1. maximum-gap(经过了提示)

    下面的分桶个数做的不太好,原来的解法是用的 int gap = (big - small) / vlen; if (gap == 0) { gap = 1; } 下面是现在的Java解法: packa ...

  2. bzoj1054: [HAOI2008]移动玩具

    hash+bfs:要注意特殊情况.(似乎连sort.lower_bound都不用数据小直接判重了... #include<cstdio> #include<cstring> # ...

  3. Asp.Net MVC Filter权限过滤使用说明

    相信对权限过滤大家都不陌生,用户要访问一个页面时,先对其权限进行判断并进行相应的处理动作. mvc中是如何实现权限验证的? mvc中是根据路由配置来请求控制器类中的一个方法 在mvc框架中为程序员提供 ...

  4. td内容自动换行 ,td超过宽度显示点点点… , td 使用 overflow:hidden 无效,英文 数字 不换行 撑破div容器

    我们可以先给表格 table上 固定一个宽度 不让表格撑破 width: 747px; table-layout:fixed; 然后我们在td上加上如下样式 style="width:100 ...

  5. 任E行M1端口比特率特征码

    分辨率:800x480gps端口:com1比特率:4800设备特征码:01D1D008内存:128M

  6. AJAX在GBK编码页面中传中文参数乱码的问题

    ---恢复内容开始--- 页面编码是GBK的情况下传递中文有乱码,解决方法如下: 在ajax传递前用若是Array,JSON,等其它对象,可用JSON.stringfy字符串序列化后,赋值给ajax传 ...

  7. MySQL基础之第11章 插入、更新与删除数据

    11.1.插入数据 11.1.1.为表的所有字段插入数据 1.INSERT语句中不指定具体的字段名         insert into 表名 values (值1,值2…值n)2.INSERT语句 ...

  8. Devexpress GridControl中combobox级联显示 z

    http://minmin86121.blog.163.com/blog/static/4968115720143163533356/ 在 使用GridControl时,可能会有需求要求某2列显示co ...

  9. Delphi TRichEdit加载word内容

    procedure TForm1.btn6Click(Sender: TObject);var WordApp: Variant; //声明一个word对象beginWordApp := Create ...

  10. 使用calabash测试开源中国Android客户端

    Calabash-android是支持android的UI自动化测试框架,前面已经介绍过<中文Win7下成功安装calabash-android步骤>,这篇博文尝试测试一个真实应用:开源中 ...