Educational Codeforces Round 2_B. Queries about less or equal elements
2 seconds
256 megabytes
standard input
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.
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).
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.
5 4
1 3 5 7 9
6 4 2 8
3 2 1 4
5 5
1 2 1 2 5
3 1 4 1 5
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的更多相关文章
- 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 ...
- 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 ...
- Educational Codeforces Round 65 (Rated for Div. 2)题解
Educational Codeforces Round 65 (Rated for Div. 2)题解 题目链接 A. Telephone Number 水题,代码如下: Code #include ...
- Educational Codeforces Round 41 967 E. Tufurama (CDQ分治 求 二维点数)
Educational Codeforces Round 41 (Rated for Div. 2) E. Tufurama (CDQ分治 求 二维点数) time limit per test 2 ...
- [Educational Codeforces Round 16]E. Generate a String
[Educational Codeforces Round 16]E. Generate a String 试题描述 zscoder wants to generate an input file f ...
- [Educational Codeforces Round 16]D. Two Arithmetic Progressions
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic pr ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- [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 ...
- [Educational Codeforces Round 16]A. King Moves
[Educational Codeforces Round 16]A. King Moves 试题描述 The only king stands on the standard chess board ...
随机推荐
- Python学习日记day10------函数的命名空间、作用域与闭合函数
1,参数陷阱 如果默认参数的只是一个可变数据类型,那么每一次调用的时候,如果不传值就共用这个数据类型的资源. 2,三元运算 c=a if a>b else b#如果a>b返回a,否则,返回 ...
- Bash shell命令记录和CentOS的一些技巧
①CentOS的实用技巧: 一.按下ctrl+alt+F2可由图形界面切换至命令行(shell窗口),按下ctrl+alt+F1可由命令行切换至图形界面(前提是安装CentOS时软件选择项选择安装了图 ...
- 5.Nginx作为web缓存服务器
Nginx作为web缓存服务器 从0.7.48版本开始,Nginx支持类似Squid的缓存功能.Nginx的web缓存服务主要由proxy_cache相关命令集合fastcgi_cache相关命令集构 ...
- New Life With 2018
2017年转眼过去了.对自己来说.这一大年是迷茫和认知的一年.我的第一篇博客就这样记录下自己的历程吧 一:选择 从进入这一行到现在已经一年多了,2016年11月份就像所有的应届毕业生一样,都贼反感毕业 ...
- java 学习(二)
public class Scoure { public static void main(String args[]) { int score=90; if (score>=85 && ...
- Io 异常: The Network Adapter could not establish the connection
新接触一个项目,导入源码,在本地启动的时候后台报了一个错误: Could not discover the dialect to use. java.sql.SQLException: Io 异常: ...
- Django内置Admin
Django内置的Admin是对于model中对应的数据表进行增删改查提供的组件,使用方式有: 依赖APP: django.contrib.auth django.contrib.contenttyp ...
- c#常用快捷键
VS快捷键大全(总结了一些记忆的口诀) 原文转载至 https://www.cnblogs.com/liyunhua/p/4537054.html#top 谢谢大牛的分享! 相信.Net ...
- ASP.NET Core学习之四 在CentOS上部署.net core
一.安装CentOs 以前在大学学过linux,但是对命令行总是有一种深深的排斥感,几年之后,还是又回来了. 1.下载 现在没法FQ,就算是FQ网速也是蜗牛一样慢,我使用阿里云的镜像站进行下载速度还是 ...
- Python当前文件路径与文件夹删除操作
前言: Python的文件操作跟Java存在部分差异.由于项目需要,近期使用python进行模块开发时遇到一些常见的文件操作便上网搜罗了一番,感觉众说纷纭.因此,结合自身的使用场景,贴一段python ...