背景 Background
描述 Description
输入格式 InputFormat
输出格式 OutputFormat
在原来小姊妹中智商的排名
分块原理题
因为无法测就没有测
我觉得应该过得了(嗝屁)
过不了请勿把我批判一番
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;
const int N = 1000000 + 5;
int n,a[N],t,last[N],x;
int query( int x ){
if( x > a[n] ) return n+1;
if( x < a[1] ) return 1;
for( int i = 1; i <= t+1; i++ )
if( x <= last[i] && x >= last[i-1])
for( int j = 1; j <= t; j++ )
if( a[(i-1)*t+j] >= x ) return (i-1)*t+j;
}
int main(){
scanf("%d", &n);
for( int i = 1; i <= n; i++ ) scanf("%d", &a[i]);
std::sort(a+1,a+n+1);
t = sqrt(n);
for( int i = 1; i <= t; i++ ) last[i] = a[i*t];
last[t+1] = a[n];
while(scanf("%d", &x)!=EOF) printf("%d\n",query(x));
return 0;
}