Submission #43411939
Source Code Expand
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define op(x) ((x&1)?x+1:x-1)
#define odd(x) (x&1)
#define even(x) (!odd(x))
#define lc(x) (x<<1)
#define rc(x) (lc(x)|1)
#define lowbit(x) (x&-x)
#define mp(x,y) make_pair(x,y)
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
using namespace std;
const ll MAXN=(1<<22),mod=998244353;
void add(ll& x,ll y){x=(x+y)%mod;}
void sub(ll& x,ll y){x=(x-y+mod)%mod;}
ll addv(ll x,ll y){return (x+y)%mod;}
ll subv(ll x,ll y){return (x-y+mod)%mod;}
void tomax(ll& x,ll y){x=max(x,y);}
void tomin(ll& x,ll y){x=min(x,y);}
ll mypow(ll a,ll n){
ll ret = 1,pw = a;
while(n){
if(n&1)ret = ret * pw%mod;
pw = pw*pw%mod;
n>>=1;
}
return ret;
}
ll myinv(ll a){
return mypow(a,mod-2);
}
const ll div3 = myinv(3);
typedef vector<ll> Poly;
int SZ(const Poly& v){return v.size();}
void up(Poly& v,int n){
if(SZ(v) < n)v.resize(n,0);
}
void cut(Poly& v,int n){
if(SZ(v) > n)v.resize(n,0);
}
void reset(Poly& v,int n){
up(v,n);
cut(v,n);
}
Poly operator+(const Poly& x,const Poly& y){
Poly z(max(SZ(x),SZ(y)),0);
rep(i,0,SZ(z)-1){
z[i] = addv((i<SZ(x)) ? (x[i]) : (0),(i<SZ(y)) ? (y[i]) : 0);
}
return z;
}
Poly operator-(const Poly& x,const Poly& y){
Poly z(max(SZ(x),SZ(y)),0);
rep(i,0,SZ(z)-1){
z[i] = subv((i<SZ(x)) ? (x[i]) : (0),(i<SZ(y)) ? (y[i]) : 0);
}
return z;
}
namespace _{
ll f[MAXN],g[MAXN],h[MAXN],W[MAXN];
int rev[MAXN],N;
void transform(ll* f){rep(i,0,N-1)if(i<rev[i])swap(f[i],f[rev[i]]);}
void DFT(ll* f,ll a){
transform(f);
ll pw = mypow(a,(mod-1)/N);
W[0]=1;rep(i,1,N-1)W[i] = W[i-1]*pw%mod;
for(int len=2;len<=N;len<<=1)for(int i=0;i<N;i+=len)rep(j,0,len/2-1){
ll w = W[j*(N/len)];
ll x = f[i+j],y = f[i+j+len/2];
f[i+j] = addv(x,w*y);
f[i+j+len/2] = subv(x,w*y%mod);
}
}
void FFT(const Poly& x,const Poly& y,Poly& z){
int n = SZ(x)-1,m = SZ(y)-1;
N=1;while(N<=n+m)N<<=1;
rep(i,0,N-1){
f[i] = g[i] = h[i] = 0;
rev[i] = rev[i>>1] >> 1;
if(i&1)rev[i] |= (N>>1);
}
rep(i,0,n)f[i] = x[i];
rep(i,0,m)g[i] = y[i];
DFT(f,3);DFT(g,3);
rep(i,0,N-1)h[i] = f[i]*g[i]%mod;
DFT(h,div3);
reset(z,n+m+1);
ll inv = myinv(N);
rep(i,0,n+m)z[i] = h[i]*inv%mod;
}
};
Poly operator*(const Poly& x,const Poly& y){
Poly z;
_::FFT(x,y,z);
return z;
}
//
namespace CFM{
const int MAXM = 2e5+10;
int n,m,p,q,ca[MAXN],cb[MAXN],M;
Poly calc(const Poly& A){
Poly ret(M);
int sz = A.size();
rep(i,0,sz-1)add(ret[i%M],A[i]);
return ret;
}
Poly mypow(const Poly& A,int n){
if(!n){
Poly I(M);
I[0] = 1;
return I;
}
Poly B = mypow(A,n/2);
B = B*B;
if(n&1)B = B*A;
return calc(B);
}
void solve(){
cin>>n>>m>>p>>q;
rep(i,1,p){
int num;cin>>num;
ca[num]++;
}
rep(i,1,q){
int num;cin>>num;
cb[num]++;
}
//
M = 2*m+2; //mod x^M -1
Poly F(M);
rep(i,1,m){
F[i] = ca[i];
F[M-i] = (mod-ca[i])%mod;
}
Poly X(M);
X[0] = X[1] = X[M-1] = 1;
//计算 F * X^(n-1)
F = F * mypow(X,n-1);
F = calc(F);
ll ans = 0;
rep(i,1,m){
add(ans,F[i] * cb[i]%mod);
}
cout<<ans<<endl;
}
};
int main(){
CFM::solve();
return 0;
}
Submission Info
Judge Result
| Set Name |
Sample |
All |
| Score / Max Score |
0 / 0 |
650 / 650 |
| Status |
|
|
| Set Name |
Test Cases |
| Sample |
example_00.txt, example_01.txt, example_02.txt |
| All |
example_00.txt, example_01.txt, example_02.txt, test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt |
| Case Name |
Status |
Exec Time |
Memory |
| example_00.txt |
AC |
8 ms |
3632 KB |
| example_01.txt |
AC |
2 ms |
3448 KB |
| example_02.txt |
AC |
6941 ms |
50940 KB |
| test_00.txt |
AC |
34 ms |
4980 KB |
| test_01.txt |
AC |
19 ms |
3660 KB |
| test_02.txt |
AC |
25 ms |
3452 KB |
| test_03.txt |
AC |
6457 ms |
52704 KB |
| test_04.txt |
AC |
7683 ms |
52048 KB |
| test_05.txt |
AC |
6740 ms |
52400 KB |
| test_06.txt |
AC |
2547 ms |
28564 KB |
| test_07.txt |
AC |
27 ms |
3732 KB |
| test_08.txt |
AC |
7756 ms |
51976 KB |
| test_09.txt |
AC |
126 ms |
5056 KB |
| test_10.txt |
AC |
1480 ms |
16604 KB |
| test_11.txt |
AC |
6809 ms |
51924 KB |
| test_12.txt |
AC |
6106 ms |
52260 KB |
| test_13.txt |
AC |
7314 ms |
53164 KB |
| test_14.txt |
AC |
7338 ms |
52104 KB |
| test_15.txt |
AC |
8009 ms |
52996 KB |
| test_16.txt |
AC |
8066 ms |
52348 KB |
| test_17.txt |
AC |
7773 ms |
52780 KB |
| test_18.txt |
AC |
7552 ms |
52228 KB |
| test_19.txt |
AC |
8567 ms |
53232 KB |
| test_20.txt |
AC |
8869 ms |
53424 KB |
| test_21.txt |
AC |
8938 ms |
53364 KB |
| test_22.txt |
AC |
8895 ms |
53172 KB |