zoukankan      html  css  js  c++  java
  • cidefirces Educational Codeforces Round 2 B Queries about less or equal elements

    B. Queries about less or equal elements

     
     

    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.

    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 test(s)
    Input
    5 4
    1 3 5 7 9
    6 4 2 8
    Output
    3 2 1 4
    Input
    5 5
    1 2 1 2 5
    3 1 4 1 5
    Output
    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 }
  • 相关阅读:
    OpenGL入门1.3:着色器 GLSL
    OpenGL入门1.2:渲染管线简介,画三角形
    C++回调,函数指针
    JavaScript 比较和逻辑运算符
    JS 运算符
    JS 函数
    JS 对象
    JS 数据类型
    JS 变量
    JS 注释
  • 原文地址:https://www.cnblogs.com/homura/p/5002171.html
Copyright © 2011-2022 走看看