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
| #include<bits/stdc++.h> using namespace std;
void read(int &x) { x=0;int f=1;char ch=getchar(); for(;!isdigit(ch);ch=getchar()) if(ch=='-') f=-f; for(;isdigit(ch);ch=getchar()) x=x*10+ch-'0';x*=f; }
void print(int x) { if(x<0) putchar('-'),x=-x; if(!x) return ;print(x/10),putchar(x%10+48); } void write(int x) {if(!x) putchar('0');else print(x);putchar('\n');}
#define lf double #define ll long long
#define pii pair<int,int > #define vec vector<int >
#define pb push_back #define mp make_pair #define fr first #define sc second
#define data asd09123jdf02i3h
#define FOR(i,l,r) for(int i=l,i##_r=r;i<=i##_r;i++)
const int maxn = 1e6+10; const int inf = 1e9; const lf eps = 1e-8; const int mod = 998244353;
int n,m,t,a[maxn],f[4],r[4],s[4],iv[4],s1[4],s2[4],_[10],*inv=_+5;
int qpow(int a,int x) { int res=1; for(;x;x>>=1,a=1ll*a*a%mod) if(x&1) res=1ll*res*a%mod; return res; }
int c(int a,int b) { int res=1; for(int i=1;i<=b;i++) res*=(a-i+1); for(int i=1;i<=b;i++) res/=i;return res; }
int get(int x) { int ans=0; for(int i=1;i<=3;i++) { int res=1;if(x==i) return f[i]; for(int j=1;j<=3;j++) if(j!=i) res=1ll*res*(x-j)%mod*inv[i-j]%mod; ans=(ans+1ll*res*f[i]%mod)%mod; }return (ans+mod)%mod; }
int main() { freopen("landlords.in","r",stdin); freopen("landlords.out","w",stdout); read(n),read(m),read(t);iv[0]=1; for(int i=1;i<=3;i++) { f[i]=pow(i,t); iv[i]=1ll*iv[i-1]*qpow(n-i+1,mod-2)%mod; } inv[1]=1,inv[2]=qpow(2,mod-2); inv[-1]=mod-1,inv[-2]=mod-inv[2]; for(int p=1;p<=m;p++) { read(a[p]); for(int i=1;i<=3;i++) r[i]=f[i]; for(int i=1;i<=3;i++) s[i]=i+a[p]<=n?get(i+a[p]):0; s1[0]=s2[0]=1; for(int i=1;i<=3;i++) { f[i]=0; s1[i]=1ll*s1[i-1]*(a[p]-i+1)%mod; s2[i]=1ll*s2[i-1]*(n-a[p]-i+1)%mod; } for(int i=1;i<=3;i++) for(int j=1;j<=i;j++) { f[i]=(f[i]+1ll*c(i-1,j-1)*s1[j]%mod*s2[i-j]%mod*iv[i]%mod*r[j]%mod)%mod; f[i]=(f[i]+1ll*c(i-1,j-1)*s2[j]%mod*s1[i-j]%mod*iv[i]%mod*s[j]%mod)%mod; } } int q,x;read(q); while(q--) read(x),write(get(x)); return 0; }
|