标签:
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
1 #include<cstdio> 2 #include<vector> 3 #include<cmath> 4 #include<queue> 5 #include<map> 6 #include<cstring> 7 #include<algorithm> 8 using namespace std; 9 typedef long long ll; 10 typedef unsigned long long ull; 11 const int maxn=2e5+5; 12 int main() 13 { 14 int n,m; 15 int a[maxn]; 16 scanf("%d%d",&n,&m); 17 for(int i=0;i<n;i++) 18 scanf("%d",&a[i]); 19 sort(a,a+n); 20 for(int i=0;i<m;i++) 21 { 22 int tt; 23 scanf("%d",&tt); 24 int pos=lower_bound(a,a+n,tt+1)-a; 25 printf("%d ",pos); 26 } 27 return 0; 28 }
cidefirces Educational Codeforces Round 2 B Queries about less or equal elements
标签:
原文地址:http://www.cnblogs.com/homura/p/5002171.html