传送门:

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. 解决 command not found: express

    需要先执行 sudo npm install -g express-generator 再安装 sudo npm install -g express 建立项目骨架 express -e   xxx

  2. centOS查看apache版本的命令

    在centOS 7下: 命令如下: httpd -v

  3. Basic Data Structures and Algorithms in the Linux Kernel--reference

    http://luisbg.blogalia.com/historias/74062 Thanks to Vijay D'Silva's brilliant answer in cstheory.st ...

  4. git代码管理工具-SourceTree 使用介绍

    一.SourceTree 简单说明 SourceTree 是git 代码管理的可视化工具,可省去操作命令行的一个图形化工具,下载地址:https://www.sourcetreeapp.com/ 二. ...

  5. 【卷土重来之C#学习笔记】(二)c#编程概述

    (1)开始C#,一个简单的程序Hello Word 开始     using System; //使用了System的命名空间 using System.Collections.Generic; us ...

  6. [LeetCode]27. Remove Element移除元素

    Given an array nums and a value val, remove all instances of that value in-place and return the new ...

  7. 《Unity Shader入门精要》读书笔记(1)

    主要是对第二章的整理 渲染流水线:由一个三维场景出发,生成(渲染)一张二维图像. 渲染流程:应用阶段.几何阶段.光栅化阶段. 应用阶段: 1. 把数据加载到显存中 渲染所需数据从硬盘,到内存,再到显存 ...

  8. Java集合篇三:Vector

    package com.test.collection; import java.util.Vector; public class MyVector { /** * @param args */ p ...

  9. Csharp and Vbscript: Encryption/Decryption Functional

      1 /// <summary>   2     /// 塗聚文   3     /// 20130621   4     /// 自定义字符串加密解密   5     /// < ...

  10. Ubuntu上使用vnc服务

    http://www.aichengxu.com/linux/8479752.htm 1. sudo apt-get install x11vnc 2. sudo x11vnc -storepassw ...