CF 706B 简单二分,水

时间:2025-01-01 08:36:14

1、CF 706B  Interesting drink

2、链接:http://codeforces.com/problemset/problem/706/B

3、总结:二分

题意:给出n个数,再给出q个mi,每次求n个数里有多少个数<=mi

#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
#include<cstdio>
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f const int N=;
int x[N]; int main()
{
int n,q,m;
while(~scanf("%d",&n))
{
for(int i=;i<=n;i++)
scanf("%d",&x[i]);
sort(x+,x+n+); scanf("%d",&q);
for(int i=;i<q;i++)
{
scanf("%d",&m);
int l=,r=n,mid;
while(l<=r){
mid=(l+r)/;
if(m<x[mid]){
r=mid-;
}else if(m>=x[mid]){
l=mid+;
}
} cout<<r<<endl;
} } return ;
}