编程思路:
以bitset的01表示来代替此维有多少符合偏序,最后取k维偏序的交集即是答案
使用分块加速原理,可以根据此维数字大小排名来分块预处理每一小块,查询时使用二分得到快速定位属于的块号,最后再暴力计算剩余的<=sqrt(n)个数字
模板代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = 50010;
int n,k,block,num,belong[maxn],l[maxn],r[maxn],f[10][maxn];
pair<int,int>val[10][maxn];
bitset<maxn>bset[10][210];
LL ans;
int bin( int p , int x )
{
int l=1,r=n;
while ( l<=r )
{
int mid = (l+r)>>1;
if ( val[p][mid].first<=x ) l = mid+1;
else r = mid-1;
}
return r;
}
bitset<maxn> getbset( int p , int x )
{
bitset<maxn>res; res.reset();
int pp = bin( p , x );
if ( pp<=0 ) return res;
int pre = pp/block;
int st = pre*block+1;
res = bset[p][pre];
for ( int i=st