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. java实现最基础的socket网络通信

    一.网络通信基础 网络中存在很多的通信实体,每一个通信实体都有一个标识符就是IP地址. 而现实中每一个网络实体可以和多个通信程序同时进行网络通信,这就需要使用端口号进行区分. 二.java中的基本网络 ...

  2. C++ STL之vector容器的基本操作

    注意事项:特别注意任何时候同时使用两个迭代器产生的将会是一个前闭后开的区间(具体见插入和删除的例子)特别注意begin()指向的是vec中的第0个元素,而end是指向最后一个元素的后面一个位置(不是最 ...

  3. css动画集合地址

    CSS3 UI Lib库是由腾讯AlloyTeam前端开发团队建立,主要收集国内外友好体验和创意的界面组件Demo. 它除了使用CSS3技术外,还使用了HTML5,JS,JX,jQuery等技术,来达 ...

  4. macro names must be identifiers

    1.错把 #include 写成了 #define 会报这个错 2.定义一个不存在的宏业会报这个错,如加了-DANDRO 而ANDRO不存在

  5. django - 好的 获取 参数值 方法

    第一步: # 参数列表 parameters = ('user_id', 'day_time', 'normal_data', 'hourly_data', 'product_id') # 需要传入的 ...

  6. 一天一个Java基础——序列化

    1.概念 Java的“对象序列化”能将一个实现了Serializable接口的对象转换成一组byte,这样日后要用这个对象的时候,能把这些byte数据恢复出来,并据此重新构建那个对象. 对象序列化能实 ...

  7. w3c盒子模型与ie盒子模型

    盒子模型是css的专有名词,用来描述页面设置中的各种属性,如内容(content).填充(padding).边框(border).边界(margin),由于这些属性拼在一起,与日常生活中的“盒子”很相 ...

  8. 解决32位plsql客户端连接不64位Oracle11g上数据库

    一.解决方案 因为本人安装的是64位的Oracle,plsql 是32位的故连接不上.网上有方法能连接. 1. 文件下载 下载PLSQL_Developer地址 http://pan.baidu.co ...

  9. [irving] C# Windows Beep 调用声音文件

    方法一:Console.Beep(); 方法二:可以用Console.WriteLine("/a");来代替Beep(). MSDN:http://msdn.microsoft.c ...

  10. 如果你喜欢Python 那么你不得不知的几个开源项目

    1.Trac Trac拥有强大的bug管理 功能,并集成了Wiki 用于文档管理.它还支持代码管理工具Subversion ,这样可以在 bug管理和Wiki中方便地参考程序源代码. Trac有着比较 ...