結果
問題 | No.206 数の積集合を求めるクエリ |
ユーザー | Ryuhei Mori |
提出日時 | 2017-03-05 17:49:59 |
言語 | C (gcc 12.3.0) |
結果 |
AC
|
実行時間 | 22 ms / 7,000 ms |
コード長 | 4,728 bytes |
コンパイル時間 | 1,590 ms |
コンパイル使用メモリ | 36,372 KB |
実行使用メモリ | 8,040 KB |
最終ジャッジ日時 | 2024-06-23 06:00:46 |
合計ジャッジ時間 | 2,830 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 15 ms
7,844 KB |
testcase_01 | AC | 14 ms
7,940 KB |
testcase_02 | AC | 15 ms
8,032 KB |
testcase_03 | AC | 15 ms
7,940 KB |
testcase_04 | AC | 15 ms
7,936 KB |
testcase_05 | AC | 14 ms
7,940 KB |
testcase_06 | AC | 14 ms
7,976 KB |
testcase_07 | AC | 14 ms
7,936 KB |
testcase_08 | AC | 14 ms
7,992 KB |
testcase_09 | AC | 14 ms
7,932 KB |
testcase_10 | AC | 14 ms
7,948 KB |
testcase_11 | AC | 15 ms
7,940 KB |
testcase_12 | AC | 15 ms
8,016 KB |
testcase_13 | AC | 15 ms
7,944 KB |
testcase_14 | AC | 14 ms
7,812 KB |
testcase_15 | AC | 15 ms
7,936 KB |
testcase_16 | AC | 15 ms
7,840 KB |
testcase_17 | AC | 19 ms
8,024 KB |
testcase_18 | AC | 16 ms
7,932 KB |
testcase_19 | AC | 18 ms
7,956 KB |
testcase_20 | AC | 16 ms
7,872 KB |
testcase_21 | AC | 17 ms
7,996 KB |
testcase_22 | AC | 17 ms
7,856 KB |
testcase_23 | AC | 18 ms
7,940 KB |
testcase_24 | AC | 21 ms
7,964 KB |
testcase_25 | AC | 22 ms
7,928 KB |
testcase_26 | AC | 19 ms
7,892 KB |
testcase_27 | AC | 18 ms
7,940 KB |
testcase_28 | AC | 20 ms
8,040 KB |
testcase_29 | AC | 20 ms
7,968 KB |
testcase_30 | AC | 18 ms
7,972 KB |
コンパイルメッセージ
main.c: In function 'read_uint': main.c:33:20: warning: implicit declaration of function 'getchar_unlocked' [-Wimplicit-function-declaration] 33 | while(c<'0') c = getchar_unlocked(); | ^~~~~~~~~~~~~~~~ main.c: In function 'write_uint': main.c:49:5: warning: implicit declaration of function 'fputs_unlocked' [-Wimplicit-function-declaration] 49 | fputs_unlocked("0\n", stdout); | ^~~~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <complex.h> #define PI2 6.28318530717958647692 const int k = 18; const int m = (1 << 18); typedef double complex cmplx; cmplx C[1<<18]; cmplx w[1<<17]; const int mod10[200] = { 0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9, 0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9,0,1,2,3,4,5,6,7,8,9 }; const int div10[200] = { 0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4, 5,5,5,5,5,5,5,5,5,5,6,6,6,6,6,6,6,6,6,6,7,7,7,7,7,7,7,7,7,7,8,8,8,8,8,8,8,8,8,8,9,9,9,9,9,9,9,9,9,9, 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,12,13,13,13,13,13,13,13,13,13,13, 14,14,14,14,14,14,14,14,14,14,15,15,15,15,15,15,15,15,15,15,16,16,16,16,16,16,16,16,16,16,17,17,17,17,17,17,17,17,17,17, 18,18,18,18,18,18,18,18,18,18,19,19,19,19,19,19,19,19,19,19 }; void read_uint(int *x){ char c=0; while(c<'0') c = getchar_unlocked(); *x = c-'0'; c = getchar_unlocked(); while(c>='0') { *x *= 10; *x += c-'0'; c = getchar_unlocked(); } } void write_uint(int x){ int i; static char buf[13]=" \n"; if(x==0){ fputs_unlocked("0\n", stdout); return; } for(i=10; x; i--){ if(x >= 200){ buf[i] = '0' + x % 10; x /= 10; } else { buf[i] = '0' + mod10[x]; x = div10[x]; } } fputs_unlocked(buf+1+i, stdout); } void fft(int k, cmplx *A, const cmplx *w){ const int m = 1 << k; int u = 1; int v = m/4; int i, j; if(k&1){ for(j=0; j<m/2; j++){ cmplx Ajv = A[j|(m/2)]; A[j|(m/2)] = A[j] - Ajv; A[j] += Ajv; } u <<= 1; v >>= 1; } for(i=k&~1;i>0;i-=2){ int jh; for(jh=0;jh<u;jh++){ cmplx wj = w[jh<<1]; cmplx wj2 = w[jh]; cmplx wj3 = wj2 * wj; int je; for(j = jh << i, je = j+v;j<je; j++){ cmplx tmp0 = A[j]; cmplx tmp1 = wj * A[j+v]; cmplx tmp2 = wj2 * A[j+2*v]; cmplx tmp3 = wj3 * A[j+3*v]; cmplx ttmp0 = tmp0 + tmp2; cmplx ttmp2 = tmp0 - tmp2; cmplx ttmp1 = tmp1 + tmp3; cmplx ttmp3 = -I * (tmp1 - tmp3); A[j] = ttmp0 + ttmp1; A[j+v] = ttmp0 - ttmp1; A[j+2*v] = ttmp2 + ttmp3; A[j+3*v] = ttmp2 - ttmp3; } } u <<= 2; v >>= 2; } } void ifft(int k, cmplx *A, const cmplx *w){ const int m = 1 << k; int u = m/4; int v = 1; int i, j; for(i=2;i<=k;i+=2){ int jh; for(jh=0;jh<u;jh++){ cmplx wj = conj(w[jh<<1]); cmplx wj2 = conj(w[jh]); cmplx wj3 = wj2 * wj; int je; for(j = jh << i, je = j+v;j<je; j++){ cmplx tmp0 = A[j]; cmplx tmp1 = A[j|v]; cmplx tmp2 = A[j|(v<<1)]; cmplx tmp3 = A[j|(v<<1)|v]; cmplx ttmp0 = tmp0 + tmp1; cmplx ttmp1 = tmp0 - tmp1; cmplx ttmp2 = tmp2 + tmp3; cmplx ttmp3 = I * (tmp2 - tmp3); A[j] = ttmp0 + ttmp2; A[j|v] = wj * (ttmp1 + ttmp3); A[j|(v<<1)] = wj2 * (ttmp0 - ttmp2); A[j|(v<<1)|v] = wj3 * (ttmp1 - ttmp3); } } u >>= 2; v <<= 2; } if(k&1){ for(j = 0;j<m/2; j++){ cmplx Ajv = A[j|(m/2)]; A[j|(m/2)] = A[j] - Ajv; A[j] += Ajv; } } } void genw(int i, int b, cmplx z){ if(b == 0){ w[i] = z; } else { genw(i, b>>1, z); genw(i|b, b>>1, z*w[b]); } } void convolver(int k, cmplx *A, const cmplx *w){ int i; const int m = 1 << k; fft(k, A, w); A[0] = 4 * creal(A[0]) * cimag(A[0]) * I; A[1] = 4 * creal(A[1]) * cimag(A[1]) * I; for(i = 2; i < m; i+=2){ int y = 1 << (31-__builtin_clz(i)); int j = i^(y-1); A[i] = (A[i] + conj(A[j]))*(A[i] - conj(A[j])); A[j] = -conj(A[i]); } for(i = 0; i < m; i+=2){ A[i/2] = (A[i]+A[i^1] - (A[i]-A[i^1])*w[i/2]*I)/(4*m); } ifft(k-1, A, w); } int main(){ int l, mm, n, q; int i, j; const double arg = -PI2/m; for(i=1, j=m/4; j; i<<=1, j>>=1){ w[i] = cexp(I * (arg * j)); } genw(0, m/4, 1); read_uint(&l); read_uint(&mm); read_uint(&n); for(i=0;i<l;i++){ int a; read_uint(&a); C[a] = 1; } for(i=0;i<mm;i++){ int a; read_uint(&a); C[(1<<18)-a] += I; } read_uint(&q); convolver(k, C, w); write_uint(cimag(C[0])+0.5); for(i=1;2*i<q;i++){ write_uint(creal(C[i])+0.5); write_uint(cimag(C[i])+0.5); } if(!(q&1)) write_uint(creal(C[q/2])+0.5); return 0; }