题解归档 - cf600B

题解归档 - cf600B

本文由 cf-code 本地题解库自动归档;公开内容以本地 AC/验证版本为准。

思路

cf600B — Queries about less or equal elements

题意

对每个 b_j 统计 a 中有多少个元素 ≤ b_j

做法

排序 aupper_bound 得 ≤ 的个数。

结论

O((n+m) log n)。

代码

来源:problems/cf600B/solution.cpp

/* Author: likely
 * Time: 2026-06-08 04:14:49
**/
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn=200005;
ll n,m,i,j,k,a[maxn+5],b[maxn+5];
int main(){
    cin>>n>>m;
    for(i=1;i<=n;i++) cin>>a[i];
    sort(a+1,a+1+n);
    for(i=1;i<=m;i++){
        cin>>b[i];
        k=upper_bound(a+1,a+1+n,b[i])-a-1;
        if(i>1) cout<<" ";
        cout<<k;
    }
    cout<<endl;
    return 0;
}
~  ~  The   End  ~  ~


 赏 
感谢您的支持,我会继续努力哒!
支付宝收款码
tips
文章二维码 分类标签:归档TypechoAutoUpload
文章标题:题解归档 - cf600B
文章链接:https://www.fangshaonian.cn/archives/362/
最后编辑:2026 年 6 月 28 日 19:08 By 方少年
许可协议: 署名-非商业性使用-相同方式共享 4.0 国际 (CC BY-NC-SA 4.0)
(*) 5 + 8 =
快来做第一个评论的人吧~