五维偏序。。一开始被吓到了,后来知道了一种BITSET分块的方法,感觉非常不错。
呆马:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <bitset>
#define inf 1000000007
#define maxn 52000
#define maxm 520 using namespace std; struct score
{
int x,y;
friend bool operator <(score a, score b)
{
return a.x<b.x;
}
}s[][maxn]; int n,m,p,num,block;
int bel[maxn],l[maxm],r[maxm];
int a[][maxn];
bitset<> b[][maxm];
bitset<> now[]; int main()
{
int Case;
scanf("%d",&Case);
for (int i=;i<=;i++) b[i][].reset();
for (int o=;o<=Case;o++)
{
scanf("%d%d",&n,&m);
for (int j=;j<=n;j++)
for (int i=;i<=;i++)
{
scanf("%d",&a[i][j]);
s[i][j].x=a[i][j];
s[i][j].y=j;
}
for (int i=;i<=;i++)
{
sort(s[i]+,s[i]+n+);
sort(a[i]+,a[i]+n+);
}
int block=sqrt(n);
int num=n/block+(n%block!=);
for (int i=;i<=n;i++) bel[i]=(i-)/block+;
for (int i=;i<=num;i++) l[i]=(i-)*block+;
for (int i=;i<=num;i++) r[i]=i*block;
r[num]=n;
for (int i=;i<=;i++)
for (int j=;j<=num;j++)
{
b[i][j]=b[i][j-];
for (int k=l[j];k<=r[j];k++)
b[i][j][s[i][k].y]=;
}
scanf("%d",&p);
int x[],ans=;
for (int q=;q<=p;q++)
{
for (int i=;i<=;i++) scanf("%d",&x[i]);
for (int i=;i<=;i++) x[i]^=ans;
for (int i=;i<=;i++) now[i].reset();
for (int i=;i<=;i++)
{
int tmp=upper_bound(a[i]+,a[i]+n+,x[i])-a[i]-;
if (tmp==) continue;
now[i]=b[i][bel[tmp]-];
for (int j=l[bel[tmp]];j<=tmp;j++)
now[i][s[i][j].y]=;
}
now[]=now[]&now[]&now[]&now[]&now[];
ans=now[].count();
printf("%d\n",ans);
}
}
return ;
}
Score