結果
問題 | No.206 数の積集合を求めるクエリ |
ユーザー | LayCurse |
提出日時 | 2015-05-08 23:34:43 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 42 ms / 7,000 ms |
コード長 | 4,624 bytes |
コンパイル時間 | 1,441 ms |
コンパイル使用メモリ | 163,760 KB |
実行使用メモリ | 19,072 KB |
最終ジャッジ日時 | 2024-07-05 20:41:48 |
合計ジャッジ時間 | 4,047 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
17,280 KB |
testcase_01 | AC | 36 ms
17,280 KB |
testcase_02 | AC | 37 ms
17,280 KB |
testcase_03 | AC | 37 ms
17,408 KB |
testcase_04 | AC | 37 ms
17,280 KB |
testcase_05 | AC | 37 ms
17,280 KB |
testcase_06 | AC | 36 ms
17,408 KB |
testcase_07 | AC | 36 ms
17,408 KB |
testcase_08 | AC | 36 ms
17,408 KB |
testcase_09 | AC | 35 ms
17,408 KB |
testcase_10 | AC | 35 ms
17,280 KB |
testcase_11 | AC | 35 ms
17,280 KB |
testcase_12 | AC | 37 ms
17,536 KB |
testcase_13 | AC | 36 ms
17,536 KB |
testcase_14 | AC | 36 ms
17,408 KB |
testcase_15 | AC | 36 ms
17,408 KB |
testcase_16 | AC | 36 ms
17,408 KB |
testcase_17 | AC | 40 ms
18,816 KB |
testcase_18 | AC | 39 ms
19,072 KB |
testcase_19 | AC | 39 ms
19,072 KB |
testcase_20 | AC | 39 ms
18,048 KB |
testcase_21 | AC | 40 ms
18,560 KB |
testcase_22 | AC | 39 ms
18,304 KB |
testcase_23 | AC | 40 ms
18,944 KB |
testcase_24 | AC | 42 ms
18,944 KB |
testcase_25 | AC | 41 ms
18,816 KB |
testcase_26 | AC | 41 ms
18,944 KB |
testcase_27 | AC | 39 ms
18,176 KB |
testcase_28 | AC | 42 ms
18,432 KB |
testcase_29 | AC | 42 ms
18,560 KB |
testcase_30 | AC | 42 ms
18,048 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);} | ~~~~~^~~~~~~~~
ソースコード
#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');} #define PI 3.141592653589793238462 struct pnt{double x,y;static double eps;pnt(void){}pnt(double a,double b){x=a;y=b;}void set(double a,double b){x=a;y=b;}pnt&operator+=(pnt a){x+=a.x;y+=a.y;return*this;}pnt&operator-=(pnt a){x-=a.x;y-=a.y;return*this;}pnt&operator*=(pnt a){pnt p=*this;x=p.x*a.x-p.y*a.y;y=p.x*a.y+p.y*a.x;return*this;}pnt operator+(pnt a){return pnt(*this)+=a;}pnt operator-(pnt a){return pnt(*this)-=a;}pnt operator*(pnt a){return pnt(*this)*=a;}}; double pnt::eps = 1e-10; void fft(int n, pnt x[], void *mem){int i,j,I,J,K,s=1;double t=2*PI/n,p;pnt w,v,u,a,b,c,d,A,B,C,D,*y=(pnt*)mem;while(n>2){I=n/4;J=I+I;K=I+J;rep(i,I){w=pnt(cos(i*t),-sin(i*t));v=w*w;u=w*v;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,B=a-c,C=b+d,D=b-d,p=D.y,D.y=D.x,D.x=-p,y[j+s*4*i]=A+C,y[j+s*(4*i+1)]=w*(B-D),y[j+s*(4*i+2)]=v*(A-C),y[j+s*(4*i+3)]=u*(B+D);}n/=4;s*=4;t*=4;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;t*=2;swap(x,y);}rep(i,s)y[i]=x[i];} void fftinv(int n, pnt x[], void *mem){int i,j,I,J,K,s=1;double t=2*PI/n,p;pnt w,v,u,a,b,c,d,A,B,C,D,*y=(pnt*)mem;while(n>2){I=n/4;J=I+I;K=I+J;rep(i,I){w=pnt(cos(i*t),sin(i*t));v=w*w;u=w*v;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,B=a-c,C=b+d,D=b-d,p=D.y,D.y=D.x,D.x=-p,y[j+s*4*i]=A+C,y[j+s*(4*i+1)]=w*(B+D),y[j+s*(4*i+2)]=v*(A-C),y[j+s*(4*i+3)]=u*(B-D);}n/=4;s*=4;t*=4;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;t*=2;swap(x,y);}rep(i,s)y[i]=x[i];} void convolution(double A[], int As, double B[], int Bs, double res[], int Rs, void *mem){int i,n,k;double m;pnt*a,*b;n=max(As+Bs,Rs);for(k=1;k<n;k*=2);a=(pnt*)mem;b=a+k;mem=b+k;rep(i,As)a[i].set(A[i],0);REP(i,As,k)a[i].set(0,0);rep(i,Bs)b[i].set(B[i],0);REP(i,Bs,k)b[i].set(0,0);fft(k,a,mem);fft(k,b,mem);rep(i,k)a[i]*=b[i];fftinv(k,a,mem);m=1.0/k;rep(i,Rs)res[i]=a[i].x*m;} void convolution(double A[], int As, double res[], int Rs, void *mem){int i,n,k;double m;pnt*a;n=max(As+As,Rs);for(k=1;k<n;k*=2);a=(pnt*)mem;mem=a+k;rep(i,As)a[i].set(A[i],0);REP(i,As,k)a[i].set(0,0);fft(k,a,mem);rep(i,k)a[i]*=a[i];fftinv(k,a,mem);m=1.0/k;rep(i,Rs)res[i]=a[i].x*m;} char memarr[77000000]; void *mem = memarr; #define MD 1000000007 int L, M, N, Q; double A[100001], B[100001], C[200001]; int main(){ int i, j, k; reader(&L,&M,&N); rep(i,L){ reader(&k); A[k] = 1; } rep(i,M){ reader(&k); B[100000-k] = 1; } reader(&Q); convolution(A, 100001, B, 100001, C, 200001, mem); rep(i,Q){ writerLn((int)(C[100000+i]+0.5)); } return 0; }