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. hash_equals()函数

    本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/92 了解下hash_equals的概念: bool hash_e ...

  2. ArcGIS API for JavaScript 中的数据类型【vs】GPServer的数据类型

    熟悉GPServer的同学肯定知道,GPServer在10.1的ArcMap后需要执行成功一次才能发布. 发布GPServer,可以是ArcMap的工具箱的工具,也可以是自己写的模型. 不管是ArcM ...

  3. Qt编写QUI皮肤生成器

    用Qt写项目写多了,为了满足不同客户的需求,需要定制不同样式的界面,QUI皮肤生成器应运而生.思考这个工具的架构花了一年时间,如何从复杂的配色方案中提取出共性,然后将共性转为具体的QSS文件.思考架构 ...

  4. C# 给DateTime赋值正确方式

    DateTime xxx = new DateTime(2007,1,1,21,21,21); string time = new DateTime(2007, 1, 1, 21, 21, 21).T ...

  5. JS对时间的操作

    JS时间操作大全 1.获取每个月的开始和结束. 2.获取每个季度的开始和结束. 3.获取当前季度. 4.把日期转换为字符串(支持各种格式) ... 5.未完待续,不断添加 String.prototy ...

  6. IDA Pro反编译代码类型转换参考

    /* This file contains definitions used by the Hex-Rays decompiler output. It has type definitions an ...

  7. python重试装饰器的简单实现

    简单实现了一个在函数执行出现异常时自动重试的装饰器,支持控制最多重试次数,每次重试间隔,每次重试间隔时间递增. 最新的代码可以访问从github上获取 https://github.com/black ...

  8. MapReduce Tutorial(划重点)

    Mapper Mapper的maps阶段将输入键值对经过计算得到中间结果键值对,框架会将中间结果按照key进行分组,然后传递给reducer以决定最终的输出.用户可以通过Job.setGrouping ...

  9. 2017 年的 人生 hard 模式终于结束了,2018年回归初心

    2017 年的 人生 hard 模式终于结束了,2018年回归初心 2017年对于我个人来讲, 毫不夸张的说 算是近十年来除了高考那一年,最最惊心动魄的一年了,没有之一. >>>开篇 ...

  10. 【三分模板】洛谷P3382三分模板

    题目描述 如题,给出一个N次函数,保证在范围[l,r]内存在一点x,使得[l,x]上单调增,[x,r]上单调减.试求出x的值. 输入输出格式 输入格式: 第一行一次包含一个正整数N和两个实数l.r,含 ...