离散化+树状数组
#include<iostream>
#include <stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
const int maxn = 100005;
int n,m;
int hash[maxn*2];
int c[maxn*2];
struct node{
int num;
int id;
friend bool operator<(const node a,const node b){
return a.num< b.num;
}
}q[maxn*2];
int lowbit(int x){
return x&(-x);
}
void update(int id,int x){
for(inti = id;i > 0;i-= lowbit(i))
c[i] +=x;
}
int getsum(int id){
int ans = 0;
for(inti = id;i < maxn*2;i += lowbit(i))
ans += c[i];
return ans;
}
int main(){
int t,cas,i;
scanf("%d",&t);
for(cas = 1;cas <= t;cas++){
scanf("%d%d",&n,&m);
for(i =1;i <=2*n+m;i++){
scanf("%d",&q[i].num);
q[i].id = i;
}
sort(q+1,q+1+2*n+m);
int k =1;
hash[q[1].id]= k;
for(i =2;i <=2*n+m;i++){
if(q[i-1].num== q[i].num)
hash[q[i].id] = k;
else
hash[q[i].id] = ++k;
}
//for(i = 1;i<= 2*n+m;i++)
// printf("%d ",hash[i]);
memset(c, 0,sizeof(c));
for(i =1;i <2*n;i+=2){
update(hash[i]-1,-1);
update(hash[i+1],1);
}
printf("Case#%d:\n",cas);
for(i =2*n+1;i<= 2*n+m;i++)
printf("%d\n",getsum(hash[i]));
}
return 0;
}