1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
#include<bits/stdc++.h> #define re register typedef long long ll; template<class T> inline void read(T &x) { x=0; char ch=getchar(),t=0; while(ch<'0'||ch>'9') t|=ch=='-',ch=getchar(); while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar(); if(t) x=-x; } template<class T,class ...T1> inline void read(T &x,T1 &...x1){ read(x),read(x1...); } template<class T> inline void write(T x) { if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); } template<> inline void write(bool x){ putchar(x?'1':'0'); } template<> inline void write(char c){ putchar(c); } template<> inline void write(char *s){ while(*s!='\0') putchar(*s++); } template<> inline void write(const char *s){ while(*s!='\0') putchar(*s++); } template<class T,class ...T1> inline void write(T x,T1 ...x1){ write(x),write(x1...); } template<class T> inline bool checkMax(T &x,T y){ return x<y?x=y,1:0; } template<class T> inline bool checkMin(T &x,T y){ return x>y?x=y,1:0; } const int MAXN=7.5e3+10,MAXM=60; int N,M,K[MAXN],a[MAXN][MAXM]; int pre[MAXN][MAXM]; namespace AnotherSolve { const int MAXS=1<<10|10; int tmp1[MAXM],tmp2[MAXM],K1,K2; bool ans[MAXS][MAXS]; int Sta[MAXN]; inline bool main() { for(int s1=0;s1<(1<<M);++s1) for(int s2=0;s2<(1<<M);++s2) { K1=K2=0; for(int i=1;i<=M;++i) { if(s1>>(i-1)&1) tmp1[++K1]=i; if(s2>>(i-1)&1) tmp2[++K2]=i; } int cur1=1,cur2=1,cnt=0,cnthole=0; while(cur1<=K1&&cur2<=K2) { if(tmp1[cur1]<=tmp2[cur2]) ++cnt,++cur1; else cnthole+=(!!cnt),++cur2,cnt=0; } cnthole+=(!!cnt),ans[s1][s2]=cnthole&1; } for(int i=1;i<=N;++i) for(int j=1;j<=K[i];++j) Sta[i]|=1<<(a[i][j]-1); int res=0; for(int i=1;i<=N;++i) for(int j=i+1;j<=N;++j) res+=ans[Sta[i]][Sta[j]]; write(res,'\n'); return 0; } }; int main() { read(N,M); for(int i=1;i<=N;++i) { read(K[i]); for(int j=1;j<=K[i];++j) read(a[i][j]),pre[i][a[i][j]]=1; std::sort(a[i]+1,a[i]+K[i]+1); for(int j=1;j<=M;++j) pre[i][j]+=pre[i][j-1]; } if(M<=10) return AnotherSolve::main(); int ans=0; for(int i=2;i<=N;++i) for(int j=1;j<i;++j) { int cnt=0; for(int k=1;k<=K[i];++k) cnt+=(pre[j][a[i][k]]>pre[j][a[i][k-1]]); ans+=cnt&1; } write(ans); return 0; }
|