結果
問題 |
No.206 数の積集合を求めるクエリ
|
ユーザー |
|
提出日時 | 2023-11-24 16:08:44 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,213 ms / 7,000 ms |
コード長 | 1,834 bytes |
コンパイル時間 | 706 ms |
コンパイル使用メモリ | 82,688 KB |
実行使用メモリ | 286,544 KB |
最終ジャッジ日時 | 2024-09-26 08:37:50 |
合計ジャッジ時間 | 20,263 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
import cmath def convolution(f,g): n = len(bin(len(f)+len(g)-1)) - 2 fft_length = 1<<n f = f + [0]*(fft_length - len(f)) g = g + [0]*(fft_length - len(g)) def fft(a): for i in range(fft_length): j = 0 for k in range(n): j |= ((i>>k)&1) << (n - 1 - k) if i<j: a[i],a[j] = a[j],a[i] for nn in range(n): b = 1<<nn for j in range(b): w = cmath.rect(1,(-cmath.pi)*j/b) for k in range(0,fft_length,2*b): s = a[j+k] t = a[j+k+b]*w a[j+k] = s+t a[j+k+b] = s-t return a def ifft(a): for i in range(fft_length): j = 0 for k in range(n): j |= ((i>>k)&1) << (n - 1 - k) if i<j: a[i],a[j] = a[j],a[i] for nn in range(n): b = 1<<nn for j in range(b): w = cmath.rect(1,(cmath.pi)*j/b) for k in range(0,fft_length,2*b): s = a[j+k] t = a[j+k+b]*w a[j+k] = s+t a[j+k+b] = s-t return [i/fft_length for i in a] F = fft(f) G = fft(g) H = [i*j for i,j in zip(F,G)] return [round(i.real) for i in ifft(H)] from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline L,M,N = map(int,input().split()) A = list(map(int,input().split())) B = list(map(int,input().split())) X = [0]*(N+1) Y = [0]*(N+1) for a in A: X[a] += 1 for b in B: Y[N-b] += 1 Q = int(input()) Z = convolution(X,Y) print(*Z[N:N+Q],sep='\n')