結果

問題 No.206 数の積集合を求めるクエリ
ユーザー LayCurseLayCurse
提出日時 2015-05-11 04:16:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 97 ms / 7,000 ms
コード長 5,323 bytes
コンパイル時間 1,268 ms
コンパイル使用メモリ 164,508 KB
実行使用メモリ 8,064 KB
最終ジャッジ日時 2024-07-05 22:20:52
合計ジャッジ時間 3,810 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 1 ms
5,376 KB
testcase_06 AC 3 ms
5,376 KB
testcase_07 AC 3 ms
5,376 KB
testcase_08 AC 3 ms
5,376 KB
testcase_09 AC 3 ms
5,376 KB
testcase_10 AC 1 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 3 ms
5,376 KB
testcase_13 AC 4 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 3 ms
5,376 KB
testcase_16 AC 3 ms
5,376 KB
testcase_17 AC 95 ms
7,936 KB
testcase_18 AC 94 ms
8,064 KB
testcase_19 AC 95 ms
8,064 KB
testcase_20 AC 87 ms
7,680 KB
testcase_21 AC 94 ms
7,680 KB
testcase_22 AC 94 ms
7,808 KB
testcase_23 AC 95 ms
7,936 KB
testcase_24 AC 97 ms
8,064 KB
testcase_25 AC 96 ms
7,808 KB
testcase_26 AC 96 ms
7,936 KB
testcase_27 AC 94 ms
7,552 KB
testcase_28 AC 95 ms
7,808 KB
testcase_29 AC 96 ms
7,808 KB
testcase_30 AC 94 ms
7,680 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘void reader(double*)’:
main.cpp:15:29: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 | void reader(double *x){scanf("%lf",x);}
      |                        ~~~~~^~~~~~~~~

ソースコード

diff #

#include<bits/stdc++.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');}

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

struct mint{
  static unsigned md;
  unsigned a;

  mint(void){};mint(int n){n%=md;if(n<0)n+=md;a=n;}mint(unsigned n){a=n%md;}mint(ll n){n%=md;if(n<0)n+=md;a=n;}mint(ull n){a=n%md;}
  mint&operator+=(mint n){a+=n.a;if(a>=md)a-=md;return*this;}mint&operator-=(mint n){if(a<n.a)a+=md-n.a;else a-=n.a; return*this;}mint&operator*=(mint n){a=((ull)a*n.a)%md;return*this;}mint&operator/=(mint n){return*this*=n.inv();}mint operator+(mint n){return mint(*this)+=n;}mint operator-(mint n){return mint(*this)-=n;}mint operator*(mint n){return mint(*this)*=n;}mint operator/(mint n){return mint(*this)/=n;}mint operator-(void){ mint r; r.a = a?md-a:0; return r; }
  void setInvalid(void){a=md;}
  bool isValid(void){return a<md;}
  mint inv(void){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 mint(u);}
  mint pw(ull n){mint r(1),a(*this);while(n){if(n&1)r*=a;n>>=1;a*=a;}return r;}
  int get(void){return a;}
};
unsigned mint::md = 1004535809;

mint mval[10], minv[10];
void mint_init(void){
  int i;
  rep(i,10) mval[i] = i;
}


void mfft(int n, mint x[], mint root, void *mem){int i,j,X,Y,Z,s=1;mint I,J,K,a,b,c,d,A,B,C,D,t,*y=(mint*)mem;t=root.pw((mint::md-1)/4*3);root=root.pw((mint::md-1)/n);while(n>2){X=n/4;Y=X+X;Z=X+Y;I=1;rep(i,X){J=I*I;K=I*J;rep(j,s)a=x[j+s*i],b=x[j+s*(i+X)],c=x[j+s*(i+Y)],d=x[j+s*(i+Z)],A=a+c,B=a-c,C=b+d,D=(b-d)*t,y[j+s*4*i]=A+C,y[j+s*(4*i+1)]=I*(B-D),y[j+s*(4*i+2)]=J*(A-C),y[j+s*(4*i+3)]=K*(B+D);I*=root;}n/=4;s*=4;root*=root;root*=root;swap(x,y);}if(n==2){rep(i,s)y[i]=x[i]+x[i+s],y[i+s]=x[i]-x[i+s];n/=2;s*=2;root*=root;swap(x,y);}rep(i,s)y[i]=x[i];}
void mfftinv(int n, mint x[], mint root, void *mem){int i,j,X,Y,Z,s=1;mint I,J,K,a,b,c,d,A,B,C,D,t,*y=(mint*)mem;root=root.inv();t=root.pw((mint::md-1)/4);root=root.pw((mint::md-1)/n);while(n>2){X=n/4;Y=X+X;Z=X+Y;I=1;rep(i,X){J=I*I;K=I*J;rep(j,s)a=x[j+s*i],b=x[j+s*(i+X)],c=x[j+s*(i+Y)],d=x[j+s*(i+Z)],A=a+c,B=a-c,C=b+d,D=(b-d)*t,y[j+s*4*i]=A+C,y[j+s*(4*i+1)]=I*(B+D),y[j+s*(4*i+2)]=J*(A-C),y[j+s*(4*i+3)]=K*(B-D);I*=root;}n/=4;s*=4;root*=root;root*=root;swap(x,y);}if(n==2){rep(i,s)y[i]=x[i]+x[i+s],y[i+s]=x[i]-x[i+s];n/=2;s*=2;root*=root;swap(x,y);}rep(i,s)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]=0;rep(i,Bs)b[i]=B[i];REP(i,Bs,m)b[i]=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).inv();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]=0;mfft(m,a,root,mem);rep(i,m)a[i]*=a[i];mfftinv(m,a,root,mem);r=mint(m).inv();rep(i,Rs)res[i]=a[i]*r;}

int L, M, N, Q;
mint A[100001], B[100001], C[200001];

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(C[N-1+i].get());

  return 0;
}
0