Queries about less or equal elements CodeForces - 600B(二分)
You are given two arrays of integers a and b. For each element of the second arraybj 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 aand 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.
Examples
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
排个序 二分即可
upper_bound即可
#include <bits/stdc++.h>
using namespace std;
vector<int> g;
vector<int> v; int main()
{
int n, m;
cin>> n >> m;
for(int i=; i<n; i++)
{
int tmp;
cin>> tmp;
v.push_back(tmp);
}
for(int i=; i<m; i++)
{
int tmp;
cin>> tmp;
g.push_back(tmp);
}
sort(v.begin(), v.end());
int len = g.size();
for(int i=; i<len; i++)
{
if(i!=)
cout<< " ";
cout<< upper_bound(v.begin(), v.end(), g[i]) - v.begin();
}
cout<<endl; return ;
}
Queries about less or equal elements CodeForces - 600B(二分)的更多相关文章
- CodeForces - 600B Queries about less or equal elements (二分查找 利用stl)
传送门: http://codeforces.com/problemset/problem/600/B Queries about less or equal elements time limit ...
- CF 600B Queries about less or equal elements --- 二分查找
CF 600B 题目大意:给定n,m,数组a(n个数),数组b(m个数),对每一个数组b中的元素,求数组a中小于等于数组该元素的个数. 解题思路:对数组a进行排序,然后对每一个元素b[i],在数组a中 ...
- 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 ...
- Educational Codeforces Round 2_B. Queries about less or equal elements
B. Queries about less or equal elements time limit per test 2 seconds memory limit per test 256 mega ...
- Codeforces 600B Queries about less or equal elements(二分查找)
Description You are given two arrays of integers a and b. For each element of the second array bj yo ...
- Educational Codeforces Round 2 B. Queries about less or equal elements
打开题目连接 题意:给2个数组(无序的)啊a,b,判断b数组中的每一个元素大于a数组中个数. ACcode: #include <iostream> #include <vector ...
- Many Equal Substrings CodeForces - 1029A (kmp next数组应用)
题目大意 题目看样例也能猜到就是输出最短的循环串. 吐槽 明明是div3第一题为啥子还会用到kmp的知识? 解法 这个题仔细看发现是求最长可去除的后缀,也就是说去除跟下一个相同的字符串还能连接起来.这 ...
- CodeForces - 363D --二分和贪心
题目:CodeForces - 363D 题意:给定n个学生,其中每个学生都有各自的私己钱,并且自己的私己钱只能用在自己买自行车,不能给别人. 给定m个自行车,每个自行车都有一个价格. 给定公有财产a ...
- Codeforces Round #425 (Div. 2) Problem C Strange Radiation (Codeforces 832C) - 二分答案 - 数论
n people are standing on a coordinate axis in points with positive integer coordinates strictly less ...
随机推荐
- mysql的常用优化知识
索引类型:主键索引,唯一索引,联合索引,普通索引,全文索引 建立索引: create index index_name on table(field_name); 删除索引: drop index i ...
- ubuntu14.04安装jupyter notebook
1.使用pip安装Jupyter notebook: pip install jupyter notebook 2.创建Jupyter默认配置文件: jupyter notebook --genera ...
- WPF编程,自定义鼠标形状的一种方法。
原文:WPF编程,自定义鼠标形状的一种方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net/qq_43307934/article/details/8727 ...
- 汇编 fsub ,fmul,fdiv,fild,CVTTPS2PI 指令
知识点: 浮点指令 fsub 一.浮点指令fsub 格式 fsub memvar // st0=st0-memvar 知识点: 浮点指令 fmul 一.浮点指令fmul 格式 fmul mem ...
- python 单体模式 的几种实现
这是本人的一篇学习笔记. 本文用 python 实现单体模式,参考了这里 一.修改父类的 __dict__ class Borg: _shared_state = {} def __init__(se ...
- Dynamics CRM2016 导入数据格式之xlsx的应用
在CRM中导入数据中新增加了一个xlsx格式,这个在之前的版本(2013中没有,2015不清楚是否有)中是没有的 本篇的目的就是为了提醒各位,不要把这个格式和csv的导入功能混淆,因为xlsx格式的用 ...
- VS相关
快速显示函数名称 ctrl+alt+T 显示函数参数说明 ctrl+shift+space,光标放在函数里面 link 1123错误,vs2010的问题. 点击工程-属性-ManifestTool-I ...
- mysql基础(一)——表、索引、视图
SQL语句不区分大小写 创建数据库 create database myData 删除数据库 drop database myData 创建表 create table company ( code ...
- 移动端效果之ScrollList
写在前面 列表一直是展示数据的一个重要方式,在手机端的列表展示又和PC端展示不同,毕竟手机端主要靠滑.之前手机端之前一直使用的IScroll,但是IScroll本身其实有很多兼容性BUG,想改动一下需 ...
- uwsgi+django架构程序内部无法获取全局变量
近期开发了一个djangoi程序,用django自带的python manage.py runserver 0.0.0.0:80 运行方式无任何问题,但用django+nginx+uwsg部署运行有时 ...