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 ...
随机推荐
- 【转】VISUAL STUDIO 2008代码指标为您节省资金
转自:https://www.geekzone.co.nz/vs2008/4773 Visual Studio 2008 Team Developer和Team Suite版本中提供的许多新功能之一是 ...
- day05-列表类型
列表类型: 用途:存放多个值,根据索引. 定义方式:在[]内用逗号分隔开多个任意类型的值 L1 = list[{a:1,b:2,c:3}] 输出的为字典的key值 常用操作+内置方法 1.按索引取值: ...
- jqgrid 获取所有行数据
如何获取jqgrid所有数据? 通过 getRowData() 方法获得当前行数据 //获取所有行数据,是一个json对象集合 var rowArr= $("#jqGrid").g ...
- MVC的BundleConfig应用
1.MVC可以通过BundleConfig类来配置css和js的统一引用,分别通过StyleBundle和ScriptBundle来创建. 2.可以在母版页中统一加载设置在BundleConfig.c ...
- Centos 发送smtp邮件
说明: 1.本文是用网易smtp服务,QQ的没试过 2.在Centos7上测试 实现: 1.关闭本机的sendmail服务或者postfix服务 ...
- Linux 平台和 Windows平台下 Unicode与UTF-8互转
Windows: unsigned char * make_utf8_string(const wchar_t *unicode) { , index = , out_index = ; unsign ...
- 洛咕 P4491 [HAOI2018]染色
显然颜色数量不会超过\(lim=\min(m,n/S)\) 考虑容斥,计算恰好出现了\(S\)次的颜色有至少\(i\)种的方案数\(f[i]\),钦定\(i\)种颜色正好放\(S\)种 有\(m\)种 ...
- Eclipse编辑器设置
1. 自己不太喜欢Eclipse按回车后自动插入参数的默认选项. 可以在Window-Preferences-Java-Editor-Content Assist选项里,将Fill method ar ...
- libgdx自制简易Flappy Bird
Flappy Bird,好吧,无需多说.今天年初不知咋的,一下子就火了,而且直接跃居榜首,在ios和android平台都是如此,实在难以理解.传说其作者每天收入能达到5w刀,着实碉堡了... 好吧,咱 ...
- Javascript与后台相互访问
(1)Javascript访问C#后台变量或函数 A.通过<%=%>的形式访问 var str = "<%=GetStr() %>"; var str = ...