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
| #include<bits/stdc++.h> #define re register typedef long long ll; typedef unsigned long long ull; 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(); x*=t?-1:1; } template<class T,class ...Arc> inline void read(T &x,Arc &...arc){ read(x),read(arc...); } template<class T> inline void write(T x) { if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+48); } inline void write(bool x){ putchar(x?'1':'0'); } inline void write(char c){ putchar(c); } inline void write(char *s){ while(*s!='\0') putchar(*s++); } inline void write(const char *s){ while(*s!='\0') putchar(*s++); } template<class T,class ...Arc> inline void write(T x,Arc ...arc){ write(x),write(arc...); } 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=1e5+10,MAXS=2.5e6+10; const int Mod=1145141; template<class T1,class T2> inline void add(T1 &x,T2 y){ x=x+y>=Mod?x+y-Mod:x+y; } int N,M,a[6][MAXN],b[6][MAXN]; int Cnt[6][MAXS]; std::vector<int>Nums; inline ll getCnt(int i,int l,int r){ return l>r?0:Cnt[i][r]-Cnt[i][l-1]; } inline ll qPow(ll a,ll b=Mod-2) { ll res=1; for(;b;b>>=1,a=a*a%Mod) (b&1)&&(res=res*a%Mod); return res; } signed main() { freopen("B.in","r",stdin); freopen("B.out","w",stdout); read(N); for(int i=1;i<=5;++i) for(int j=1;j<=N;++j) read(a[i][j]),b[i][j]=6*a[i][j]+i,Nums.push_back(b[i][j]); std::sort(Nums.begin(),Nums.end()); Nums.erase(std::unique(Nums.begin(),Nums.end()),Nums.end()); for(int i=1;i<=5;++i) for(int j=1;j<=N;++j) b[i][j]=std::lower_bound(Nums.begin(),Nums.end(),b[i][j])-Nums.begin()+1; M=Nums.size()+1; for(int i=1;i<=5;++i) { for(int j=1;j<=N;++j) ++Cnt[i][b[i][j]]; for(int j=1;j<=M;++j) Cnt[i][j]+=Cnt[i][j-1]; } ll ans=0,Inv=qPow(qPow(N,5)); for(int i=1;i<=5;++i) for(int j=1;j<=N;++j) { ll sum=0; for(int k1=1;k1<=5;++k1) if(k1!=i) for(int k2=k1+1;k2<=5;++k2) if(k2!=i) for(int k3=1;k3<=5;++k3) if(k3!=i&&k3!=k1&&k3!=k2) for(int k4=k3+1;k4<=5;++k4) if(k4!=i&&k4!=k1&&k4!=k2) { ll sum1=getCnt(k1,1,b[i][j]-1)*getCnt(k2,1,b[i][j]-1)%Mod; ll sum2=getCnt(k3,b[i][j]+1,M)*getCnt(k4,b[i][j]+1,M)%Mod; add(sum,sum1*sum2%Mod); } add(ans,sum*Inv%Mod*a[i][j]%Mod); } write(ans); return 0; }
|