传送门:

http://codeforces.com/problemset/problem/600/B

Queries about less or equal elements
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

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 a that 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.

Examples
Input

Copy
5 4
1 3 5 7 9
6 4 2 8
Output

Copy
3 2 1 4
Input

Copy
5 5
1 2 1 2 5
3 1 4 1 5
Output

Copy
4 2 4 2 5

分析:
题目意思:
输入数组A和B,要求输出数组A中比B[i]小的数的个数。
做法:
暴力会超时,利用二分查找
upper_bound(A, A+N,  B[i])- A;返回大于B[i]按照正序应存放的地址,取地址后是下标。 code:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define max_v 200005
int a[max_v],b[max_v];
int main()
{
int n,m;
while(cin>>n>>m)
{
for(int i=;i<n;i++)
cin>>a[i];
for(int i=;i<m;i++)
cin>>b[i];
sort(a,a+n);
for(int i=;i<m;i++)
{
if(i==m-)
{
printf("%d\n",upper_bound(a,a+n,b[i])-a);
}else
{
printf("%d ",upper_bound(a,a+n,b[i])-a);
}
}
}
return ;
}

CodeForces - 600B Queries about less or equal elements (二分查找 利用stl)的更多相关文章

  1. 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 yo ...

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

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

  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. TOJ 3744 Transportation Costs

    描述 Minya Konka decided to go to Fuzhou to participate in the ACM regional contest at their own expen ...

  2. Nmap原理02 - 编写自己的服务探测脚本

    编写自己的服务探测脚本 1. 添加自己的探测脚本 nmap-service-probes文件的格式将在第二节介绍,本节通过一个例子说明如何添加自己的服务探测脚本. AMQP协议,即Advanced M ...

  3. openlayers 3 读取展示shp文件

    简单的思路如下: 1.在arcgis中获得shp文件 2.将其转成geojson文件 3.用openlayers进行展示 第一步直接省略 第二步这里推荐一个shp转geojson很方便的工具网站htt ...

  4. linux基础-linux和unix的区别

    有时候我们对天天使用的Linux指令,只知道怎么用,却分不清概念用法区别,我觉得很有必要整理整理大家熟视无睹的一些linux概念区别. 首先说说unix和linux的区别: linux和unix的最大 ...

  5. scss-字符串连接符

    + 运算可用于连接字符串: // SCSS p { cursor: e + -resize; } // 编译后的 CSS 样式 p { cursor: e-resize; } 请注意,如果带引号的字符 ...

  6. SQLAlchemy的使用---外键ForeignKey数据增删改查

    # 添加数据 from sqlalchemy.orm import sessionmaker from create_table_ForeignKey import engine, Student, ...

  7. 从零开始的全栈工程师——利用CSS3画一个正方体 ( css3 )

    transform属性 CSS3的变形(transform)属性让元素在一个坐标系统中变形.transform属性的基本语法如下: transform:none | <transform-fun ...

  8. JS图片赖加载例子

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. sublime text 3 添加代码片段

    工具>插件开发>新建代码片段 <snippet> <content> <![CDATA[ Hello, ${1:this} is a ${2:snippet} ...

  10. dialog和dialogFragment的使用及常用问题

    今天比较懒,只是列举了一些网址 弹窗之一:dialogFragment的使用 https://blog.csdn.net/sinat_31057219/article/details/76979246 ...