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.

Sample test(s)
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
二分||
#include <bits/stdc++.h>
using namespace std; typedef long long int LL ; const int maxn = 2e5+100; LL a[maxn], b[maxn], c[maxn];
int n, m;
int erfen(LL p) {
int le = 1, ri = n, mid;
mid = (le+ri)/2;
for (int i = 1; i<300; i++) {
if (p>=a[mid]) le = mid;
else if (p<a[mid]) ri = mid;
mid = (le+ri)/2;
}
if (p == a[mid] && p!=a[ri]) return mid;
else if (p == a[mid] && p==a[ri]) return ri;
if (p>a[mid] && p<a[ri]) return mid;
else if (p>a[mid] && p >= a[ri]) return ri;
else if (p<a[mid] && p<a[le]) return mid-1;
else if (p<a[mid] && p>=a[le]) return le;
} int main() {
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
memset(c, 0, sizeof(c)); cin >> n >> m;
for (int i = 1; i<=n; i++)
cin >> a[i];
for (int i = 1; i<=m; i++)
cin >> b[i];
sort(a+1, a+n+1);
//sort(b, b+m);
int num = 0;
for (int i = 1; i<=m; i++) {
c[num++] = erfen(b[i]);
}
for (int i = 0; i<num-1; i++)
cout << c[i] << " ";
cout << c[num-1] << endl;
return 0;
}

Educational Codeforces Round 2_B. Queries about less or equal elements的更多相关文章

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

  2. Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings

    Codeforces Educational Codeforces Round 44 (Rated for Div. 2) F. Isomorphic Strings 题目连接: http://cod ...

  3. Educational Codeforces Round 65 (Rated for Div. 2)题解

    Educational Codeforces Round 65 (Rated for Div. 2)题解 题目链接 A. Telephone Number 水题,代码如下: Code #include ...

  4. Educational Codeforces Round 41 967 E. Tufurama (CDQ分治 求 二维点数)

    Educational Codeforces Round 41 (Rated for Div. 2) E. Tufurama (CDQ分治 求 二维点数) time limit per test 2 ...

  5. [Educational Codeforces Round 16]E. Generate a String

    [Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...

  6. [Educational Codeforces Round 16]D. Two Arithmetic Progressions

    [Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...

  7. [Educational Codeforces Round 16]C. Magic Odd Square

    [Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...

  8. [Educational Codeforces Round 16]B. Optimal Point on a Line

    [Educational Codeforces Round 16]B. Optimal Point on a Line 试题描述 You are given n points on a line wi ...

  9. [Educational Codeforces Round 16]A. King Moves

    [Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...

随机推荐

  1. UIImage类方法总结及UIImage生成方法对比

    http://mp.weixin.qq.com/s/A900w0Y5pGjuaB4j9Os9ww1.UIImage 生成方法的对比 Apple官方的文档为生成一个UIImage对象提供了两种方法: 1 ...

  2. 用node搭建简单的静态资源管理器

    我们都知道,老牌的3p服务器都是自带静态资源管理器的.但是node不同,它没有web容器,它的路由地址和真实地址可以没有联系,所有node的优点,是可以把路由做得相当漂亮. 但静态资源管理器也是必不可 ...

  3. Linux第四节 组管理、用户管理、权限管理 / chmod /chown / umask / vim

    三期第三讲1.组管理/用户管理(重要文件系统会实时备份 file-) vim/etc/group: 组管理文件://组名:密码控位键:组id:成员 vim/etc/gshadow:组密码管理文件:// ...

  4. 为什么说Python 是大数据全栈式开发语言

    欢迎大家访问我的个人网站<刘江的博客和教程>:www.liujiangblog.com 主要分享Python 及Django教程以及相关的博客 交流QQ群:453131687 原文链接 h ...

  5. sql存储过程中使用 output

    1.sql存储过程中使用 output CREATE PROCEDURE [dbo].[P_Max] @a int, -- 输入 @b int, -- 输入 @Returnc int output - ...

  6. 快速开发 jQuery 插件的 10 大技巧

    在开发过很多 jQuery 插件以后,我慢慢的摸索出了一套开发jQuery插件比较标准的结构和模式.这样我就可以 copy & paste 大部分的代码结构,只要专注最主要的逻辑代码就行了. ...

  7. C# DataGridView 列的显示顺序

    this.dataGridView1.Columns["列名"].DisplayIndex=Convert.ToInt32("你要放置的位置")

  8. java多线程(三)-Executors实现的几种线程池以及Callable

    从java5开始,类库中引入了很多新的管理调度线程的API,最常用的就是Executor(执行器)框架.Executor帮助程序员管理Thread对象,简化了并发编程,它其实就是在 提供了一个中间层, ...

  9. x的x次幂的值为10,求x的近似值

    public class Main { static double eps = 1e-7; public static void main(String[] args){ double l = 2,r ...

  10. jQuery 实现无限任意添加下拉菜单

    新学jQuery还有很多没学,今天做了个下拉菜单,按照自己的思想结合学的基础效果实现一款可以任意添加层数的下拉菜单,如果有什么建议,欢迎指教啦啦啦 我喜欢备注细一些,这样给自己也是一种理解和方便回顾哈 ...