#include<bits/stdc++.h> #define ll long long #define maxn 50 constint mod=998244353;
usingnamespace std;
ll qpow(ll x,ll n) { ll ans=1; while (n) { if (n&1) ans=1ll*ans*x%mod; x=1ll*x*x%mod; n>>=1; } return ans; }
structRect{ int x1,y1,x2,y2; }rec[maxn]; int n,W,H; int w[50],h[50],w1=0,h1=0; int state[(1<<10)+1],cnt[(1<<10)+1]; int vis[50][50]; ll dp[(1<<10)+1]; intcheck() { for (int x=1;x<W;x++) for (int y=1;y<H;y++) if (vis[x][y]==0) { return0; } return1; } intmain() { // cin>>n; int T; cin>>T; while (T--) { w1=0; memset(cnt,0,sizeof(cnt)); memset(dp,0,sizeof(dp)); h1=0; cin>>n; cin>>W>>H; w[++w1]=W; h[++h1]=H; for (int i=1;i<=n;i++) { cin>>rec[i].x1>>rec[i].y1; w[++w1]=(rec[i].x1); h[++h1]=rec[i].y1; cin>>rec[i].x2>>rec[i].y2; w[++w1]=(rec[i].x2); h[++h1]=rec[i].y2; } sort(w+1,w+1+w1); sort(h+1 ,h+1+h1); w1=unique(w+1,w+1+w1)-w-1; h1=unique(h+1,h+1+h1)-h-1; W=lower_bound(w+1,w+1+w1,W)-w; H=lower_bound(h+1,h+1+h1,H)-h; for (int i=1;i<=n;i++) { rec[i].x1=lower_bound(w+1,w+1+w1,rec[i].x1)-w; rec[i].x2=lower_bound(w+1,w+1+w1,rec[i].x2)-w; rec[i].y1=lower_bound(h+1,h+1+h1,rec[i].y1)-h; rec[i].y2=lower_bound(h+1,h+1+h1,rec[i].y2)-h; } int S=(1<<n)-1;
for (int s=S;s>=0;s--) { state[s]=1; memset(vis,0,sizeof(vis)); for (int k=1;k<=n;k++) { if (s&(1<<(k-1))) { cnt[s]++; for (int x=rec[k].x1;x<rec[k].x2;x++) for (int y=rec[k].y1;y<rec[k].y2;y++) vis[x][y]=1; } } state[s]=check();
} if (!state[S]) { puts("-1"); continue; } for (int s=S;s>=0;s--) { if (state[s]==1) { dp[s]=0; continue; } ll sum=0; for (int k=1;k<=n;k++) { if (!(s&(1<<(k-1)))) { sum=(sum+dp[s|(1<<(k-1))])%mod; } ll inv=qpow(n-cnt[s],mod-2); dp[s]=(ll)(sum+n)*inv%mod; dp[s]%=mod; } } cout<<dp[0]<<endl; } }
// // Created by Administrator on 2022/4/22. // #include<bits/stdc++.h> #define maxn 100010 #define ll long long usingnamespace std; int sq,n,q; int a[maxn]; ll ans[maxn],res; int cl[maxn],cr[maxn]; int L,R; structSeg{ int id,l,r; booloperator < (const Seg & b) const{ if (l/sq!=b.l/sq) return l<b.l; if (l/sq&1) return r<b.r; return r>b.r; } }req[maxn];
intmain() { cin>>n; sq=sqrt(n); for (int i=1;i<=n;i++) cin>>a[i]; cin>>q; for (int i=1;i<=q;i++) { req[i].id=i; cin>>req[i].l>>req[i].r; } sort(req+1,req+1+q); L=1,R=n; res=0; for (int i=1;i<=q;i++) { while (L<req[i].l) { res+=cr[a[L]]; cl[a[L]]++; L++; } while (L>req[i].l) { L--; cl[a[L]]--; res-=cr[a[L]]; } while (R<req[i].r) { R++; cr[a[R]]--; res-=cl[a[R]]; } while (R>req[i].r) { res+=cl[a[R]]; cr[a[R]]++; R--; } ans[req[i].id]=1ll*L*(ll)(n-R+1)-res; } for (int i=1;i<=q;i++) cout<<ans[i]<<endl; return0; }