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 you should find the number of elements in array athat 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 Input
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<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#define MAX 200100
using namespace std;
int a[MAX],b[MAX];
int c[MAX],d[MAX];
int main()
{
int n,m,j,i;
int s;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(i=0;i<n;i++)
scanf("%d",&a[i]);
for(i=0;i<m;i++)
scanf("%d",&b[i]);
sort(a,a+n);
for(i=0;i<m;i++)
{
if(i==m-1)
printf("%d\n",upper_bound(a,a+n,b[i])-a);
else
printf("%d ",upper_bound(a,a+n,b[i])-a);
}
// __int64 Max=-1;
// memset(a,0,sizeof(0));
// memset(b,0,sizeof(b));
// memset(d,0,sizeof(d));
// for(i=1;i<=n;i++)
// {
// scanf("%I64d",&s);
// if(s>0)
// d[s]++;
// a[s]=s;
// Max=max(Max,s);
// }
// for(i=1;i<=m;i++)
// {
// scanf("%I64d",&s);
// b[i]=s;
// }
// for(i=1;i<=Max;i++)
// {
// if(a[i]==0)
// a[i]=i+1;
// }
// sort(a,a+n);
// memset(c,0,sizeof(c));
// for(i=1;i<=Max;i++)
// {
// if(a[i]<=i)
// c[i]+=(c[i-1]+d[i]);
// else
// c[i]=c[i-1];
// }
// for(i=1;i<m;i++)
// printf("%I64d ",c[b[i]]);
// printf("%I64d\n",c[b[m]]);
}
return 0;
}
Codeforces 600B Queries about less or equal elements(二分查找)的更多相关文章
- CF 600B Queries about less or equal elements --- 二分查找
CF 600B 题目大意:给定n,m,数组a(n个数),数组b(m个数),对每一个数组b中的元素,求数组a中小于等于数组该元素的个数. 解题思路:对数组a进行排序,然后对每一个元素b[i],在数组a中 ...
- CodeForces - 600B Queries about less or equal elements (二分查找 利用stl)
传送门: http://codeforces.com/problemset/problem/600/B Queries about less or equal elements time limit ...
- 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 ...
- 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 ...
- Educational Codeforces Round 2 B. Queries about less or equal elements
打开题目连接 题意:给2个数组(无序的)啊a,b,判断b数组中的每一个元素大于a数组中个数. ACcode: #include <iostream> #include <vector ...
- codeforces:MEX Queries分析和实现
首先说明一下MEX,设S是自然数集合N的一个子集,那么S的MEX则为min(N\S),即不包含于S的最小自然数. 题目大意是存在一个空集S,提供n组输入(n<10^5),每组输入对应下面的一个指 ...
- Codeforces Round #768 (Div. 2) D. Range and Partition // 思维 + 贪心 + 二分查找
The link to problem:Problem - D - Codeforces D. Range and Partition time limit per test: 2 second ...
- Codeforces 475D 题解(二分查找+ST表)
题面: 传送门:http://codeforces.com/problemset/problem/475/D Given a sequence of integers a1, -, an and q ...
随机推荐
- Ubuntu使用总结
错误 鼠标闪烁解决 系统设置->显示—>未知显示器->关闭->应用->选择当前配置 提示sudo: unable to resolve host ,亦即无法解析主机. 原 ...
- Android Studio修改包名和applicationId的方法
背景: 如果新做的项目跟以前做的某一个项目十分相似,那么一个简单的方法就是把原来项目拷贝一份,然后修改代码,但是这样包名还是原来项目的包名,还有如果想在同一台手机上同时安装新做的app和原来的app会 ...
- hdu 4864 Task (贪心 技巧)
题目链接 一道很有技巧的贪心题目. 题意:有n个机器,m个任务.每个机器至多能完成一个任务.对于每个机器,有一个最大运行时间xi和等级yi, 对于每个任务,也有一个运行时间xj和等级yj.只有当xi& ...
- java 基础学习
a+b: import java.util.Scanner; public class Main { public static void main(String args[]){ Scanner c ...
- UVa 10253 (组合数 递推) Series-Parallel Networks
<训练之南>上的例题难度真心不小,勉强能看懂解析,其思路实在是意想不到. 题目虽然说得千奇百怪,但最终还是要转化成我们熟悉的东西. 经过书上的神分析,最终将所求变为: 共n个叶子,每个非叶 ...
- 图表框架HelloCharts(3)饼状图
1 效果图 2 xml文件 activity_pie_chart.xml <FrameLayout xmlns:android="http://schemas.android.com/ ...
- Java知识点:javac命令
javac命令初窥 注:以下红色标记的参数在下文中有所讲解. 用法: javac <options> <source files> 其中, 可能的选项包括: -g ...
- JS调用客户端EXE
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Java [Leetcode 112]Path Sum
题目描述: Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding ...
- TCP协议的一些问题
1 连接握手三次 解释1:已失效的连接请求报文段 情况下如下:client发出的第一个连接请求报文段并没有丢失,而是在某个网络结点长时间的滞留了,以致延误到连接释放以后的某个时间才到达server.本 ...