Educational Codeforces Round 2B. Queries about less or equal elements(二分查找)

来源:互联网 发布:给淘宝差评怎么写 编辑:程序博客网 时间:2024/06/11 07:41

题目链接
题意:给你一个数组a ,然后给你一个数组B,让你找出b[i]在A中有多少是小于他的
解法:排序a数组,二分查找即可

#define CF#ifndef CF#include<cstdio>#include<algorithm>#include<cstring>#include<cmath>#else#include<bits/stdc++.h>#endif // CFusing namespace std;#define LL long long#define pb push_back#define X first#define Y second#define cl(a,b) memset(a,b,sizeof(a))typedef pair<long long ,long long > P;const int maxn=2*100005;const LL inf=1LL<<50;const LL mod=1e9+7;LL a[maxn],b[maxn];int main(){    int n,m;    cin>>n>>m;    for(int i=0;i<n;i++){        scanf("%lld",&a[i]);    }    for(int i=0;i<m;i++){        scanf("%lld",&b[i]);    }    sort(a,a+n);    for(int i=0;i<m;i++){        int p=upper_bound(a,a+n,b[i])-a;        if(i==0)printf("%d",p);        else printf(" %d",p);    }    puts("");    return 0;}
0 0
原创粉丝点击