Queries about less or equal elements CodeForces - 600B(二分)
Posted wtsruvf
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 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 aand 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.
Examples
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
排个序 二分即可
upper_bound即可
#include <bits/stdc++.h> using namespace std; vector<int> g; vector<int> v; int main() { int n, m; cin>> n >> m; for(int i=0; i<n; i++) { int tmp; cin>> tmp; v.push_back(tmp); } for(int i=0; i<m; i++) { int tmp; cin>> tmp; g.push_back(tmp); } sort(v.begin(), v.end()); int len = g.size(); for(int i=0; i<len; i++) { if(i!=0) cout<< " "; cout<< upper_bound(v.begin(), v.end(), g[i]) - v.begin(); } cout<<endl; return 0; }
以上是关于Queries about less or equal elements CodeForces - 600B(二分)的主要内容,如果未能解决你的问题,请参考以下文章
CF600B Queries about less or equal elements 题解 二分
sqli-labs less64 GET -Challenge -Blind -130 queries allowed -Variation3 (GET型 挑战 盲注 只允许130次查询 变化3)(代
sqli-labs less57 GET -Challenge -Union -14 queries allowed -Variation4 (GET型 挑战 联合查询 只允许14次查询 变化4)(代
sqli-labs less56 GET -Challenge -Union -14 queries allowed -Variation3 (GET型 挑战 联合查询 只允许14次查询 变化3)(代
sqli-labs less65 GET -Challenge -Blind -130 queries allowed -Variation4 (GET型 挑战 盲注 只允许130次查询 变化4)(代
sqli-labs less61 GET -Challenge -Double Query -5 queries allowed -Variation4 (GET型 挑战 双查询 只允许5次查询 (代