結果

問題 No.206 数の積集合を求めるクエリ
ユーザー shotoyoo
提出日時 2020-09-23 22:55:43
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 706 ms / 7,000 ms
コード長 963 bytes
コンパイル時間 112 ms
コンパイル使用メモリ 12,672 KB
実行使用メモリ 70,932 KB
最終ジャッジ日時 2024-06-28 04:39:59
合計ジャッジ時間 20,659 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 28
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


l,m,n = list(map(int, input().split()))
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
q = int(input())
a = [0]*n
b = [0]*n
for i in range(l):
    a[aa[i]-1] = 1
for i in range(m):
    b[bb[i]-1] = 1
b = b[::-1]
# FFT
import numpy as np
M = 998244353
a = np.array(a, dtype=np.int64)
b = np.array(b, dtype=np.int64)
def fft(a,b):
    l = 1
    while 2 * l < len(a) + len(b) - 1:
        l *= 2
    l *= 2
    c = np.fft.irfft((np.fft.rfft(a,l))*(np.fft.rfft(b,l)),l)
    c = np.rint(c).astype(np.int64)
    return c
def fft_large(a,b):
    d = 30000
    a1, a2 = np.divmod(a,d)
    b1, b2 = np.divmod(b,d)
    aa = fft(a1,b1)
    bb = fft(a2,b2)
    cc = (fft(a1+a2, b1+b2) - (aa+bb))
    h = (((aa*d))*d  + cc*d + bb)
    return h
c = fft(a,b)
write("\n".join(map(str, c[n-1:n-1+q].tolist())))
0