# tyvj1463 智商问题

(这么邪恶的兴趣...)

0<=智商<=2^31-1
0<=N<=1000000

1 2 3 4 5

5

5

## 备注

C语言用scanf输入输出!

Bob HAN

#include<iostream>
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 1000005;
int x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
long long n,m,a[maxn],b[maxn],cnt[maxn],sum[maxn];
int main(){
cin>>n;
for(int i = 1;i <= n;i++) a[i] = sf_read();
sort(a+1,a+1+n);
a[0] = -1;
for(int i = 1;i <= n;i++){
if(a[i] != a[i-1]){
b[++m] = a[i];
cnt[m] = 1;
sum[m] = sum[m-1] + 1;
}else{
cnt[m]++;
sum[m]++;
}
}
b[0] = -1;
int l,r,mid,ans,mm;
while(scanf("%d",&mm) == 1){
l = 0;
r = m;
while(l <= r){
mid = (l + r) >> 1;
if(b[mid] <= mm){
ans = mid;
l = mid + 1;
}else{
r = mid - 1;
}
}
if(mm == b[ans])printf("%d\n",sum[ans-1] + 1);
else printf("%d\n",sum[ans] + 1);
}
return 0;
}

posted @ 2016-08-20 22:43  ACforever  阅读(180)  评论(0编辑  收藏  举报