結果

問題 No.206 数の積集合を求めるクエリ
ユーザー LayCurseLayCurse
提出日時 2015-05-16 03:26:10
言語 C++11
(gcc 11.4.0)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 17,197 bytes
コンパイル時間 2,081 ms
コンパイル使用メモリ 178,220 KB
実行使用メモリ 814,276 KB
最終ジャッジ日時 2024-07-06 04:40:58
合計ジャッジ時間 10,664 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In member function ‘unsigned int mint::setmod(unsigned int)’:
main.cpp:48:675: warning: no return statement in function returning non-void [-Wreturn-type]
   48 |   unsigned setmod(unsigned m){int i;unsigned t;W=32;md=m;R=(1ULL<<W)%md;RR=(ull)R*R%md;switch(m){case 104857601:Rinv=2560000;mdninv=104857599;break;case 998244353:Rinv=232013824;mdninv=998244351;break;case 1000000007:Rinv=518424770;mdninv=2226617417U;break;case 1000000009:Rinv=171601999;mdninv=737024967;break;case 1004535809:Rinv=234947584;mdninv=1004535807;break;case 1007681537:Rinv=236421376;mdninv=1007681535;break;case 1012924417:Rinv=238887936;mdninv=1012924415;break;case 1045430273:Rinv=254466304;mdninv=1045430271;break;case 1051721729:Rinv=257538304;mdninv=1051721727;break;default:Rinv=get_inv(R,md);mdninv=0;t=0;rep(i,W){if(t%2==0)t+=md,mdninv|=(1U<<i);t/=2;}}}
      |                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   ^
main.cpp: In function ‘void reader(double*)’:
main.cpp:16:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   16 | void reader(double *x){scanf("%lf",x);}
      |                        ~~~~~^~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.h>
#include<xmmintrin.h>
using namespace std;

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)

#define ll long long
#define ull unsigned ll

void reader(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(ll *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(double *x){scanf("%lf",x);}
int reader(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;}c[s]='\0';return s;}
template <class T, class S> void reader(T *x, S *y){reader(x);reader(y);}
template <class T, class S, class U> void reader(T *x, S *y, U *z){reader(x);reader(y);reader(z);}
template <class T, class S, class U, class V> void reader(T *x, S *y, U *z, V *w){reader(x);reader(y);reader(z);reader(w);}

void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(ll x, char c){int s=0,m=0;char f[20];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(double x, char c){printf("%.15f",x);mypc(c);}
void writer(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);}
void writer(const char x[], char c){int i;for(i=0;x[i]!='\0';i++)mypc(x[i]);mypc(c);}
template<class T> void writerLn(T x){writer(x,'\n');}
template<class T, class S> void writerLn(T x, S y){writer(x,' ');writer(y,'\n');}
template<class T, class S, class U> void writerLn(T x, S y, U z){writer(x,' ');writer(y,' ');writer(z,'\n');}
template<class T> void writerArr(T x[], int n){int i;if(!n){mypc('\n');return;}rep(i,n-1)writer(x[i],' ');writer(x[n-1],'\n');}

ull pw(ull a, ull b, ull m){ull r=1;while(b){if(b&1)r=r*a%m;b>>=1;a=a*a%m;}return r;}
int get_inv(ll a, int md){ll t=a,s=md,u=1,v=0,e;while(s){e=t/s;t-=e*s;u-=e*v;swap(t,s);swap(u,v);}if(u<0)u+=md;return u;}

void mfft(int n, int x[], int root, int md, void *mem){int i,j,I,J,K,s=1,p,w,v,u,a,b,c,d,A,B,C,D,*y=(int*)mem;p=pw(root,(md-1)/4*3,md);root=pw(root,(md-1)/n,md);while(n>2){I=n/4;J=I+I;K=I+J;w=1;rep(i,I){v=(ll)w*w%md;u=(ll)w*v%md;rep(j,s){a=x[j+s*i];b=x[j+s*(i+I)];c=x[j+s*(i+J)];d=x[j+s*(i+K)];A=a+c;if(A>=md)A-=md;B=a-c;if(B<0)B+=md;C=b+d;if(C>=md)C-=md;D=b-d;if(D<0)D+=md;D=(ll)D*p%md;y[j+s*4*i]=A+C;y[j+s*(4*i+1)]=(ll)w*(B-D)%md;y[j+s*(4*i+2)]=(ll)v*(A-C)%md;y[j+s*(4*i+3)]=(ll)u*(B+D)%md;if(y[j+s*4*i]>=md)y[j+s*4*i]-=md;if(y[j+s*(4*i+1)]<0)y[j+s*(4*i+1)]+=md;if(y[j+s*(4*i+2)]<0)y[j+s*(4*i+2)]+=md;}w = (ll)w*root%md;}n/=4;s*=4;root=(ll)root*root%md;root=(ll)root*root%md;swap(x,y);}if(n==2){rep(i,s){y[i]=x[i]+x[i+s];if(y[i]>=md)y[i]-=md;y[i+s]=x[i]-x[i+s];if(y[i+s]<0)y[i+s]+=md;}n/=2;s*=2;root=(ll)root*root%md;swap(x,y);}rep(i,s)y[i]=x[i];}
void mfftinv(int n, int x[], int root, int md, void *mem){int i,j,I,J,K,s=1,p,w,v,u,a,b,c,d,A,B,C,D,*y=(int*)mem;root=get_inv(root,md);p=pw(root,(md-1)/4,md);root=pw(root,(md-1)/n,md);while(n>2){I=n/4;J=I+I;K=I+J;w=1;rep(i,I){v=(ll)w*w%md;u=(ll)w*v%md;rep(j,s){a=x[j+s*i];b=x[j+s*(i+I)];c=x[j+s*(i+J)];d=x[j+s*(i+K)];A=a+c;if(A>=md)A-=md;B=a-c;if(B<0)B+=md;C=b+d;if(C>=md)C-=md;D=b-d;if(D<0)D+=md;D=(ll)D*p%md;y[j+s*4*i]=A+C;y[j+s*(4*i+1)]=(ll)w*(B+D)%md;y[j+s*(4*i+2)]=(ll)v*(A-C)%md;y[j+s*(4*i+3)]=(ll)u*(B-D)%md;if(y[j+s*4*i]>=md)y[j+s*4*i]-=md;if(y[j+s*(4*i+2)]<0)y[j+s*(4*i+2)]+=md;if(y[j+s*(4*i+3)]<0)y[j+s*(4*i+3)]+=md;}w=(ll)w*root%md;}n/=4;s*=4;root=(ll)root*root%md;root=(ll)root*root%md;swap(x,y);}if(n==2){rep(i,s){y[i]=x[i]+x[i+s];if(y[i]>=md)y[i]-=md;y[i+s]=x[i]-x[i+s];if(y[i+s]<0)y[i+s]+=md;}n/=2;s*=2;root=(ll)root*root%md;swap(x,y);}rep(i,s)y[i]=x[i];}
template<class S, class T, class U> void modconvolution(S A[], int As, T B[], int Bs, U res[], int Rs, void *mem, int md, int root, int ordered=1){int i,n,k,r,*a,*b;n=max(As+Bs,Rs);for(k=1;k<n;k*=2);a=(int*)mem;b=a+k;mem=b+k;if(ordered){rep(i,As)a[i]=A[i];rep(i,Bs)b[i]=B[i];}else{rep(i,As){a[i]=A[i]%md;if(a[i]<0)a[i]+=md;}rep(i,Bs){b[i]=B[i]%md;if(b[i]<0)b[i]+=md;}}REP(i,As,k)a[i]=0;REP(i,Bs,k)b[i]=0;mfft(k,a,root,md,mem);mfft(k,b,root,md,mem);rep(i,k)a[i]=(ll)a[i]*b[i]%md;mfftinv(k,a,root,md,mem);r=get_inv(k,md);rep(i,Rs)res[i]=(ll)a[i]*r%md;}
template<class S, class T> void modconvolution(S A[], int As, T res[], int Rs, void *mem, int md, int root, int ordered=1){int i,n,k,r,*a;n=max(2*As,Rs);for(k=1;k<n;k*=2);a=(int*)mem;mem=a+k;if(ordered)rep(i,As)a[i]=A[i];else rep(i,As){a[i]=A[i]%md;if(a[i]<0)a[i]+=md;}REP(i,As,k)a[i]=0;mfft(k,a,root,md,mem);rep(i,k)a[i]=(ll)a[i]*a[i]%md;mfftinv(k,a,root,md,mem);r=get_inv(k,md);rep(i,Rs)res[i]=(ll)a[i]*r%md;}

char memarr[77000000]; void *mem = memarr;
#define MD 1004535809

struct mint{
  static unsigned md, W, R, Rinv, mdninv, RR;
  unsigned val;

  mint(){}mint(int a){val=mulR(a);}mint(unsigned a){val=mulR(a);}mint(ll a){val=mulR(a);}mint(ull a){val=mulR(a);}
  unsigned setmod(unsigned m){int i;unsigned t;W=32;md=m;R=(1ULL<<W)%md;RR=(ull)R*R%md;switch(m){case 104857601:Rinv=2560000;mdninv=104857599;break;case 998244353:Rinv=232013824;mdninv=998244351;break;case 1000000007:Rinv=518424770;mdninv=2226617417U;break;case 1000000009:Rinv=171601999;mdninv=737024967;break;case 1004535809:Rinv=234947584;mdninv=1004535807;break;case 1007681537:Rinv=236421376;mdninv=1007681535;break;case 1012924417:Rinv=238887936;mdninv=1012924415;break;case 1045430273:Rinv=254466304;mdninv=1045430271;break;case 1051721729:Rinv=257538304;mdninv=1051721727;break;default:Rinv=get_inv(R,md);mdninv=0;t=0;rep(i,W){if(t%2==0)t+=md,mdninv|=(1U<<i);t/=2;}}}
  unsigned mulR(unsigned a){return(ull)a*R%md;}unsigned mulR(int a){if(a<0)a=a%md+md;return mulR((unsigned)a);}unsigned mulR(ull a){return mulR((unsigned)(a%md));}unsigned mulR(ll a){if(a<0)a=a%md+md;return mulR((unsigned)a);}
  unsigned reduce(unsigned T){unsigned m=T*mdninv;unsigned t=(unsigned)((T+(ull)m*md)>>W);if(t>=md)t-=md;return t;}unsigned reduce(ull T){unsigned m=(unsigned)T*mdninv;unsigned t=(unsigned)((T+(ull)m*md)>>W);if(t>=md)t-=md;return t;}
  unsigned get(){return reduce(val);}
  mint&operator+=(mint a){val+=a.val;if(val>=md)val-=md;return*this;}mint&operator-=(mint a){if(val<a.val)val=val+md-a.val;else val-=a.val;return*this;}mint&operator*=(mint a){val=reduce((ull)val*a.val);return*this;}mint&operator/=(mint a){return*this*=a.inverse();}
  mint operator+(mint a){return mint(*this)+=a;}mint operator-(mint a){return mint(*this)-=a;}mint operator*(mint a){return mint(*this)*=a;}mint operator/(mint a){return mint(*this)/=a;}
  mint operator+(int a){return mint(*this)+=mint(a);}mint operator-(int a){return mint(*this)-=mint(a);}mint operator*(int a){return mint(*this)*=mint(a);}mint operator/(int a){return mint(*this)/=mint(a);}
  mint operator+(ll a){return mint(*this)+=mint(a);}mint operator-(ll a){return mint(*this)-=mint(a);}mint operator*(ll a){return mint(*this)*=mint(a);}mint operator/(ll a){return mint(*this)/=mint(a);}
  mint operator-(void){mint res;if(val)res.val=md-val;else res.val=0;return res;}
  operator bool(void){return val!=0;}operator int(void){return get();}operator ll(void){return get();}
  mint inverse(){int a=val,b=md,u=1,v=0,t;mint r;while(b){t=a/b;a-=t*b;swap(a,b);u-=t*v;swap(u,v);}if(u<0)u+=md;r.val=(ull)u*RR%md;return r;}
  mint pw(ull b){mint a(*this),r;r.val=R;while(b){if(b&1)r*=a;b>>=1;a*=a;}return r;}
};
unsigned mint::md, mint::W, mint::R, mint::Rinv, mint::mdninv, mint::RR;
mint operator+(int a, mint b){return mint(a)+=b;}mint operator-(int a, mint b){return mint(a)-=b;}mint operator*(int a, mint b){return mint(a)*=b;}mint operator/(int a, mint b){return mint(a)/=b;}
mint operator+(ll a, mint b){return mint(a)+=b;}mint operator-(ll a, mint b){return mint(a)-=b;}mint operator*(ll a, mint b){return mint(a)*=b;}mint operator/(ll a, mint b){return mint(a)/=b;}

mint mval[10000], minv[10000];
void mint_init(int md=MD, mint val[]=mval, int vals=10000, mint inv[]=minv, int invs=10000){int i;val[0].setmod(md);val[0].val=0;REP(i,1,vals){val[i].val=val[i-1].val+mint::R;if(val[i].val >=md)val[i].val-=md;}inv[1].val=1;REP(i,2,invs){inv[i].val=md-((ll)(md/i)*inv[md%i].val%md);}REP(i,1,invs)inv[i].val=(ull)inv[i].val*mint::R%md;}

static inline __m128i addmod(const __m128i &a, const __m128i &b, const __m128i &md){
  static const __m128i zeros = _mm_set_epi32(0,0,0,0);
  __m128i tmp = _mm_add_epi32(a, b);
  __m128i mask = _mm_or_si128(_mm_or_si128(_mm_cmpgt_epi32(tmp, md), _mm_cmpeq_epi32(tmp, md)), _mm_cmplt_epi32(tmp,zeros));
  return _mm_sub_epi32(tmp, _mm_and_si128(mask, md));
}

static inline __m128i submod(const __m128i &a, const __m128i &b, const __m128i &md){
  __m128i tmp = _mm_sub_epi32(a, b);
  __m128i mask = _mm_cmpgt_epi32(b, a);
  return _mm_add_epi32(tmp, _mm_and_si128(mask, md));
}

static inline __m128i mullo(const __m128i &a, const __m128i &b){
  __m128i tmp1 = _mm_mul_epu32(a,b);
  __m128i tmp2 = _mm_mul_epu32( _mm_srli_si128(a,4), _mm_srli_si128(b,4));
  return _mm_unpacklo_epi32(_mm_shuffle_epi32(tmp1, _MM_SHUFFLE(0,0,2,0)), _mm_shuffle_epi32(tmp2, _MM_SHUFFLE(0,0,2,0)));
}

static inline __m128i mulhi(const __m128i &a, const __m128i &b){
  __m128i tmp1 = _mm_mul_epu32(a,b);
  __m128i tmp2 = _mm_mul_epu32( _mm_srli_si128(a,4), _mm_srli_si128(b,4));
  return _mm_unpacklo_epi32(_mm_shuffle_epi32(tmp1, _MM_SHUFFLE(0,0,3,1)), _mm_shuffle_epi32(tmp2, _MM_SHUFFLE(0,0,3,1)));
}

static inline __m128i mulmod(const __m128i &a, const __m128i &b, const __m128i &md, const __m128i &mdninv){
  static const __m128i mask0 = _mm_set_epi32(0,0,0,-1);
  static const __m128i mask1 = _mm_set_epi32(0,0,-1,0);
  static const __m128i mask2 = _mm_set_epi32(0,-1,0,0);
  static const __m128i mask3 = _mm_set_epi32(-1,0,0,0);
  static const __m128i zeros = _mm_set_epi32(0,0,0,0);

  __m128i mask;
  __m128i t = mullo(a, b);
  __m128i t1 = _mm_mul_epu32(a,b);
  __m128i t2 = _mm_mul_epu32(_mm_srli_si128(a,4),_mm_srli_si128(b,4));
  __m128i m = mullo(t, mdninv);

  __m128i tmp1 = _mm_mul_epu32(m,md);
  __m128i tmp2 = _mm_mul_epu32(_mm_srli_si128(m,4), _mm_srli_si128(md,4));

  tmp1 = _mm_add_epi64(tmp1,t1);
  tmp2 = _mm_add_epi64(tmp2,t2);

  t = _mm_unpacklo_epi32(_mm_shuffle_epi32(tmp1, _MM_SHUFFLE(0,0,3,1)), _mm_shuffle_epi32(tmp2, _MM_SHUFFLE(0,0,3,1)));
  mask = _mm_or_si128(_mm_or_si128(_mm_cmpgt_epi32(t, md), _mm_cmpeq_epi32(t, md)), _mm_cmplt_epi32(t,zeros));

  return _mm_sub_epi32(t, _mm_and_si128(mask, md));
}


void mfft(int n, mint x[], mint root, void *mem){
  int i, j, k;
  int n1, n2, n3, step = 1;
  mint w1, w2, w3, a, b, c, d, aa, bb, cc, dd, tmp, *y = (mint*)mem;
  __m128i A, B, C, D, AA, BB, CC, DD, md, t1, t2, mask, TMP, W1, W2, W3, MDNINV;

  tmp = root.pw((mint::md-1)/4*3);
  root = root.pw((mint::md-1)/n);

  md = _mm_set_epi32(mint::md, mint::md, mint::md, mint::md);
  TMP = _mm_set_epi32(tmp.val, tmp.val, tmp.val, tmp.val);
  MDNINV = _mm_set_epi32(mint::mdninv, mint::mdninv, mint::mdninv, mint::mdninv);

  while(n > 2){
    n1 = n / 4;
    n2 = n1 + n1;
    n3 = n1 + n2;
    w1.val = mint::R;
    rep(i,n1){
      w2 = w1*w1;
      w3 = w1*w2;
      W1 = _mm_set_epi32(w1.val, w1.val, w1.val, w1.val);
      W2 = _mm_set_epi32(w2.val, w2.val, w2.val, w2.val);
      W3 = _mm_set_epi32(w3.val, w3.val, w3.val, w3.val);
      for(j=0;j+3<step;j+=4){
        A = _mm_loadu_si128((__m128i*)(x+j+step*i));
        B = _mm_loadu_si128((__m128i*)(x+j+step*(i+n1)));
        C = _mm_loadu_si128((__m128i*)(x+j+step*(i+n2)));
        D = _mm_loadu_si128((__m128i*)(x+j+step*(i+n3)));

        AA = addmod(A, C, md);
        BB = submod(A, C, md);
        CC = addmod(B, D, md);
        DD = submod(B, D, md);
        DD = mulmod(DD, TMP, md, MDNINV);

        A = addmod(AA, CC, md);
        B = submod(BB, DD, md); B = mulmod(W1, B, md, MDNINV);
        C = submod(AA, CC, md); C = mulmod(W2, C, md, MDNINV);
        D = addmod(BB, DD, md); D = mulmod(W3, D, md, MDNINV);

        _mm_storeu_si128((__m128i*)(y+j+step*(4*i  )), A);
        _mm_storeu_si128((__m128i*)(y+j+step*(4*i+1)), B);
        _mm_storeu_si128((__m128i*)(y+j+step*(4*i+2)), C);
        _mm_storeu_si128((__m128i*)(y+j+step*(4*i+3)), D);
      }
      REP(j,j,step){
        a = x[j+step*i];
        b = x[j+step*(i+n1)];
        c = x[j+step*(i+n2)];
        d = x[j+step*(i+n3)];
        aa = a + c;
        bb = a - c;
        cc = b + d;
        dd = (b - d) * tmp;
        y[j+step*(4*i  )] = aa + cc;
        y[j+step*(4*i+1)] = w1*(bb - dd);
        y[j+step*(4*i+2)] = w2*(aa - cc);
        y[j+step*(4*i+3)] = w3*(bb + dd);
      }
      w1 *= root;
    }
    n /= 4;
    step *= 4;
    root *= root;
    root *= root;
    swap(x,y);
  }

  if(n==2){
    for(i=0;i+3<step;i+=4){
      A = _mm_loadu_si128((__m128i*)(x+i));
      B = _mm_loadu_si128((__m128i*)(x+i+step));
      C = addmod(A, B, md);
      D = submod(A, B, md);
      _mm_storeu_si128((__m128i*)(y+i), C);
      _mm_storeu_si128((__m128i*)(y+i+step), D);
    }
    REP(i,i,step){
      y[i] = x[i] + x[i+step];
      y[i+step] = x[i] - x[i+step];
    }
    n /= 2;
    step *= 2;
    root *= root;
    swap(x,y);
  }
  
  rep(i,step) y[i] = x[i];
}



void mfftinv(int n, mint x[], mint root, void *mem){
  int i, j;
  int n1, n2, n3, step = 1;
  mint w1, w2, w3, a, b, c, d, aa, bb, cc, dd, tmp, *y = (mint*)mem;
  __m128i A, B, C, D, AA, BB, CC, DD, md, t1, t2, mask, TMP, W1, W2, W3, MDNINV;

  root = root.inverse();
  tmp = root.pw((mint::md-1)/4);
  root = root.pw((mint::md-1)/n);

  md = _mm_set_epi32(mint::md, mint::md, mint::md, mint::md);
  TMP = _mm_set_epi32(tmp.val, tmp.val, tmp.val, tmp.val);
  MDNINV = _mm_set_epi32(mint::mdninv, mint::mdninv, mint::mdninv, mint::mdninv);

  while(n > 2){
    n1 = n / 4;
    n2 = n1 + n1;
    n3 = n1 + n2;
    w1.val = mint::R;
    rep(i,n1){
      w2 = w1*w1;
      w3 = w1*w2;
      W1 = _mm_set_epi32(w1.val, w1.val, w1.val, w1.val);
      W2 = _mm_set_epi32(w2.val, w2.val, w2.val, w2.val);
      W3 = _mm_set_epi32(w3.val, w3.val, w3.val, w3.val);
      for(j=0;j+3<step;j+=4){
        A = _mm_loadu_si128((__m128i*)(x+j+step*i));
        B = _mm_loadu_si128((__m128i*)(x+j+step*(i+n1)));
        C = _mm_loadu_si128((__m128i*)(x+j+step*(i+n2)));
        D = _mm_loadu_si128((__m128i*)(x+j+step*(i+n3)));

        AA = addmod(A, C, md);
        BB = submod(A, C, md);
        CC = addmod(B, D, md);
        DD = submod(B, D, md);
        DD = mulmod(DD, TMP, md, MDNINV);

        A = addmod(AA, CC, md);
        B = addmod(BB, DD, md); B = mulmod(W1, B, md, MDNINV);
        C = submod(AA, CC, md); C = mulmod(W2, C, md, MDNINV);
        D = submod(BB, DD, md); D = mulmod(W3, D, md, MDNINV);

        _mm_storeu_si128((__m128i*)(y+j+step*(4*i  )), A);
        _mm_storeu_si128((__m128i*)(y+j+step*(4*i+1)), B);
        _mm_storeu_si128((__m128i*)(y+j+step*(4*i+2)), C);
        _mm_storeu_si128((__m128i*)(y+j+step*(4*i+3)), D);
      }
      REP(j,j,step){
        a = x[j+step*i];
        b = x[j+step*(i+n1)];
        c = x[j+step*(i+n2)];
        d = x[j+step*(i+n3)];
        aa = a + c;
        bb = a - c;
        cc = b + d;
        dd = (b - d) * tmp;
        y[j+step*(4*i  )] = aa + cc;
        y[j+step*(4*i+1)] = w1*(bb + dd);
        y[j+step*(4*i+2)] = w2*(aa - cc);
        y[j+step*(4*i+3)] = w3*(bb - dd);
      }
      w1 *= root;
    }
    n /= 4;
    step *= 4;
    root *= root;
    root *= root;
    swap(x,y);
  }

  if(n==2){
    for(i=0;i+3<step;i+=4){
      A = _mm_loadu_si128((__m128i*)(x+i));
      B = _mm_loadu_si128((__m128i*)(x+i+step));
      C = addmod(A, B, md);
      D = submod(A, B, md);
      _mm_storeu_si128((__m128i*)(y+i), C);
      _mm_storeu_si128((__m128i*)(y+i+step), D);
    }
    REP(i,i,step){
      y[i] = x[i] + x[i+step];
      y[i+step] = x[i] - x[i+step];
    }
    n /= 2;
    step *= 2;
    root *= root;
    swap(x,y);
  }
  
  rep(i,step) y[i] = x[i];
}

void modconvolution(mint A[], int As, mint B[], int Bs, mint res[], int Rs, void *mem, mint root){int i,n,m;mint*a,*b,r;n=max(As+Bs,Rs);for(m=1;m<n;m*=2);a=(mint*)mem;b=a+m;mem=b+m;rep(i,As)a[i]=A[i];REP(i,As,m)a[i].val=0;rep(i,Bs)b[i]=B[i];REP(i,Bs,m)b[i].val=0;mfft(m,a,root,mem);mfft(m,b,root,mem);rep(i,m)a[i]*=b[i];mfftinv(m,a,root,mem);r=mint(m).inverse();rep(i,Rs)res[i]=a[i]*r;}
void modconvolution(mint A[], int As, mint res[], int Rs, void *mem, mint root){int i,n,m;mint*a,r;n=max(2*As, Rs);for(m=1;m<n;m*=2);a=(mint*)mem;mem=a+m;rep(i,As)a[i]=A[i];REP(i,As,m)a[i].val=0;mfft(m,a,root,mem);rep(i,m)a[i]*=a[i];mfftinv(m,a,root,mem);r=mint(m).inverse();rep(i,Rs)res[i]=a[i]*r;}

int L, M, N, Q;
mint A[1000001], B[1000001], C[2000001];

int main(){
  int i, j, k;

  mint_init();

  reader(&L,&M,&N);
  rep(i,L){
    reader(&k);
    A[k-1] = mval[1];
  }
  rep(i,M){
    reader(&k);
    B[N-k] = mval[1];
  }
  reader(&Q);
  
  modconvolution(A, N, B, N, C, 2*N, mem, mval[3]);

  rep(i,Q) writerLn((int)C[N-1+i]);

  return 0;
}
0