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. 关于llvm kaleidoscope: 记一次Debug血泪之路

    简而言之,慎(bu)用(yong)全局变量! 这次debug基本上花了我一周的时间,我基本上是晚上9点30下自习回然后调试到11点30,如此反复一周直到今天周五终于解决了,,以前都听说前辈们 说尽量不 ...

  2. Ubuntu14.04下安装 boost (boost_1.54 最简单的方法)

    直接执行命令: sudo apt-get  install libboost-dev 测试: 创建一个 boost_test.cpp 文件,写入 #include<iostream> #i ...

  3. coursera 视频总是缓冲或者无法观看的解决办法

    注意!!!该方法针对Windows用户,亲测有效. 1.用管理员权限记事本打开host文件 2.将如下内容复制到文件末尾 52.84.246.90 d3c33hcgiwev3.cloudfront.n ...

  4. nova创建虚拟机源码分析系列之四 nova代码模拟

    在前面的三篇博文中,介绍了restful和SWGI的实现.结合restful和WSGI配置就能够简单的实现nova服务模型的最简单的操作. 如下的内容是借鉴网上博文,因为写的很巧妙,将nova管理虚拟 ...

  5. type 命令详解

     type  作用: 用来显示指定命令的类型,判断出命令是内部命令还是外部命令. 命令类型: alias: 别名 keyword:关键字, shell 保留字 function:函数, shell函数 ...

  6. Rstudio( bioconductor)下载太慢,用国内镜像

    在Rstudio中,下载软件install.packages()和 bioconductor软件下载命令 source("http://bioconductor.org/biocLite.R ...

  7. MySQL中各种数据类型的长度及在开发中如何选择

    接触MySQL这个数据库大概快要两年了,不过由于没有特别深入系统的去学习,大多也是停留在一知半解的状态.今天在工作中刚好碰到了表设计的问题,顺便写篇博客,把MySQL中数据类型和字段类型选择这方面给弄 ...

  8. 怎样在Win7系统建立并开启Wifi热点

    怎样在Win7系统建立并开启Wifi热点 步骤/方法: 1.首先,确定你的笔记本已经开启了无线. 点击电脑左下角的开始,在搜索程序和文件栏输入cmd. 2.在上图中找到Windows命令处理程序cmd ...

  9. 解决 iPhone 微信 H5 无法自动播放音乐问题

    使用 wx sdk 在html导入sdk js文件.(如果网站是https导入的sdk也要使用https!) 然后在 wx.ready 中设置 play 方法并复制给全局变量 fm,当需要使用的时候再 ...

  10. Ubuntu Bash and Dash

    http://blog.sina.cn/dpool/blog/s/blog_5f16b0590100r1ub.html?vt=4