传送门:

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. Whu 1604——Play Apple——————【博弈】

    Problem 1604 - Play Apple Time Limit: 1000MS   Memory Limit: 65536KB   Total Submit: 442  Accepted: ...

  2. 【Xshell】设置XShell最大的显示行数

    选择会话,依次点击“文件"->"属性”,打开“会话属性”窗体   在“会话属性”窗体中,选择“终端”,下图中红框标注的地方是“缓冲区大小”,修改其中的值,其范围在0~2,14 ...

  3. Java版多人聊天室

    server.java import java.io.*; import java.net.*; import java.text.SimpleDateFormat; import java.util ...

  4. Hashtable语法简介

    Hashtable简述 Hashtable是System.Collections命名空间提供的一个容器 Hashtable中keyvalue键值对均为object类型,所以Hashtable可以支持任 ...

  5. 前端小课堂 js:what is the function?

    js 函数: 概念:函数是由事件驱动的或者当它被调用时执行的可重复使用的代码块. 说白了就是响应用户操作所执行的代码,通过js事件触发,然后调用执行函数里代码的操作. 比如常见的用户点击事件,用户点击 ...

  6. iOS Touch ID 简易开发教程

    转自:NsstringFromName 支持系统和机型 iOS系统的指纹识别功能最低支持的机型为iPhone 5s,最低支持系统为iOS 8,虽然安装iOS 7系统的5s机型可以使用系统提供的指纹解锁 ...

  7. 检查你要加入到gradle的第三方library是否是最新版本

    开发者从博客.github readme  或者 官方文档中找到如何在gradle 文件中加入dependency  的时候,往往版本已经比较老旧了,想要找到最新版,介绍一个利器 http://gra ...

  8. 通过 Powershell 来替换 ARM 模式下虚拟机的网络接口

    需求描述 客户在部署完 ARM 模式的虚拟机以后,由于误操作在虚拟机内部禁用了网卡导致远程访问虚拟机受到限制,以下是通过 Powershell 命令来替换原有虚拟网络接口实现虚拟网卡重置功能. Not ...

  9. 把IDENTITY_INSERT 设置为 ON ,还不能插入数据问题

    IDENTITY_INSERT 为 ON 时 , 必须把需要插入的列名列出来 不然报错 正确例子: SET IDENTITY_INSERT  table(表名) ONinsert into table ...

  10. mysql在表的某一位置增加一列、删除一列、修改列名

    如果想在一个已经建好的表中添加一列,可以用以下代码: ) not null; 这条语句会向已有的表中加入一列,这一列在表的最后一列位置.如果我们希望添加在指定的一列,可以用: ) not null a ...