結果

問題 No.206 数の積集合を求めるクエリ
ユーザー LayCurseLayCurse
提出日時 2015-05-09 00:09:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 130 ms / 7,000 ms
コード長 5,326 bytes
コンパイル時間 1,398 ms
コンパイル使用メモリ 163,528 KB
実行使用メモリ 7,936 KB
最終ジャッジ日時 2024-07-05 20:51:18
合計ジャッジ時間 4,418 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
5,248 KB
testcase_01 AC 1 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 4 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 4 ms
5,376 KB
testcase_09 AC 4 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 5 ms
5,376 KB
testcase_13 AC 5 ms
5,376 KB
testcase_14 AC 4 ms
5,376 KB
testcase_15 AC 4 ms
5,376 KB
testcase_16 AC 4 ms
5,376 KB
testcase_17 AC 125 ms
7,808 KB
testcase_18 AC 124 ms
7,936 KB
testcase_19 AC 124 ms
7,808 KB
testcase_20 AC 112 ms
7,680 KB
testcase_21 AC 125 ms
7,808 KB
testcase_22 AC 121 ms
7,808 KB
testcase_23 AC 125 ms
7,936 KB
testcase_24 AC 128 ms
7,936 KB
testcase_25 AC 128 ms
7,936 KB
testcase_26 AC 126 ms
7,936 KB
testcase_27 AC 125 ms
7,680 KB
testcase_28 AC 129 ms
7,808 KB
testcase_29 AC 124 ms
7,936 KB
testcase_30 AC 130 ms
7,552 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');}

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

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

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

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

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

  return 0;
}
0