hiho#1513 : 小Hi的烦恼 五维偏序

链接

hiho

思路

高维偏序用bitset,复杂度\((\frac{n^2}{32})\)

代码

#include <bits/stdc++.h>
using namespace std;
const int N=3e4+7;
int read() {
    int x=0,f=1;char s=getchar();
    for(;s>'9'||s<'0';s=getchar()) if(s=='-') f=-1;
    for(;s>='0'&&s<='9';s=getchar()) x=x*10+s-'0';
    return x*f;
}
int n,rk[N][5];
bitset<N> f[N],tmp[5];
int main() {
    n=read();
    for(int i=0;i<n;++i)
        for(int j=0;j<5;++j)
            rk[n-read()][j]=i;
    for(int i=0;i<n;++i) f[i].set();
    for(int k=0;k<5;++k) {
        tmp[k].set();
        for(int i=0;i<n;++i) {
            tmp[k][rk[i][k]]=0;
            f[rk[i][k]]&=tmp[k];
        }
    }
    for(int i=0;i<n;++i) printf("%d\n",f[i].count()-N+n);
    return 0;
}