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 ...
随机推荐
- linux命令(shell)
1.cat查看一个文件,linux默认bash 2.echo回显命令 3.ls 4.history历史记录,查看使用过的命令 5.根目录下文件目录 6.bin目录下内容多为应用程序和命令 7.boot ...
- 【ASP.NET系列】详解Views
描述 本片文章内容属于ASP.NET MVC系列视图篇,主要讲解View,大致内容如下: 1.Views文件夹讲解 2.View种类 3.Razor语法 4.对视图的基本操作 一 Views文件夹 ...
- bzoj 1492: [NOI2007]货币兑换Cash
Description 小Y最近在一家金券交易所工作.该金券交易所只发行交易两种金券:A纪念券(以下简称A券)和 B纪念券(以下 简称B券).每个持有金券的顾客都有一个自己的帐户.金券的数目可以是一个 ...
- bzoj 4813: [Cqoi2017]小Q的棋盘
Description 小Q正在设计一种棋类游戏.在小Q设计的游戏中,棋子可以放在棋盘上的格点中.某些格点之间有连线,棋子只能 在有连线的格点之间移动.整个棋盘上共有V个格点,编号为0,1,2-,V- ...
- Cat 客户端如何构建调用链消息树
场景 & 代码 Inner0 中的某方法调用了 Inner1,代码 Inner1的代码很简单, Cat通过一个线程本地变量来保存调用链的相关信息,其中核心的数据结构是消息树和操作栈.消息树用来 ...
- [知了堂学习笔记]_用JS制作《飞机大作战》游戏_第3讲(玩家发射子弹)
一.公布上一讲中玩家飞机上.下.右移动实现的代码: /*=========================键盘按下事件 keycode为得到键盘相应键对应的数字==================== ...
- Java UDP实现聊天功能代码
我以前经常写的是基于TCP的网络编程,由于TCP建立连接鼻血要经过三次握手连接,服务器端需要阻塞式等待客户端的连接.而UDP则是可以直接向目的地址的目的端口上发送数据包,由于它只负责发送出去就好,不管 ...
- C#语言和SQL Server 数据库处理
---恢复内容开始--- 第七章 用表组织数据 1:数据性分类: 1>实体完整性的约束:检验每行数据是否符合要求 检验每列数据是否符合要求 2>域完整性约束:给定列输入的有效性 3> ...
- 基于JerseyToken安全设计
网上Jersey中文资料不多,更别提其他了.本人跟进项目具体需求弄了简单的api认证机制 基本流程图 后端登录退出代码: @Path("Account") public class ...
- 如何在 iOS 真机运行 Appium
使用 gui 启动的 appium 1.2.2 也会有这个问题,所以你要把 deviceconsole 复制到 /Applications/Appium.app/Contents/Resources/ ...