結果

問題 No.1307 Rotate and Accumulate
ユーザー chineristACchineristAC
提出日時 2020-12-04 00:27:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 512 ms / 5,000 ms
コード長 2,128 bytes
コンパイル時間 759 ms
コンパイル使用メモリ 87,356 KB
実行使用メモリ 243,500 KB
最終ジャッジ日時 2023-10-12 11:04:29
合計ジャッジ時間 8,354 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 90 ms
80,716 KB
testcase_01 AC 88 ms
80,808 KB
testcase_02 AC 89 ms
80,880 KB
testcase_03 AC 95 ms
81,444 KB
testcase_04 AC 95 ms
81,200 KB
testcase_05 AC 97 ms
81,304 KB
testcase_06 AC 96 ms
81,276 KB
testcase_07 AC 87 ms
80,668 KB
testcase_08 AC 451 ms
239,376 KB
testcase_09 AC 474 ms
223,808 KB
testcase_10 AC 334 ms
158,948 KB
testcase_11 AC 305 ms
153,072 KB
testcase_12 AC 333 ms
157,980 KB
testcase_13 AC 148 ms
98,740 KB
testcase_14 AC 218 ms
129,404 KB
testcase_15 AC 510 ms
243,136 KB
testcase_16 AC 511 ms
242,948 KB
testcase_17 AC 511 ms
242,916 KB
testcase_18 AC 512 ms
243,500 KB
testcase_19 AC 503 ms
243,440 KB
testcase_20 AC 507 ms
243,132 KB
testcase_21 AC 89 ms
80,848 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

mod = 998244353
omega = pow(3,119,mod)
rev_omega = pow(omega,mod-2,mod)

N = 2*10**5
g1 = [1]*(N+1) # 元テーブル
g2 = [1]*(N+1) #逆元テーブル
inv = [1]*(N+1) #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1[i]=( ( g1[i-1] * i ) % mod )
    inv[i]=( ( -inv[mod % i] * (mod//i) ) % mod )
    g2[i]=( (g2[i-1] * inv[i]) % mod )
inv[0]=0

def _ntt(f,L,reverse=False):
    F=[f[i] for i in range(L)]
    n = L.bit_length() - 1
    base = omega
    if reverse:
        base = rev_omega

    if not n:
        return F

    size = 2**n
    wj = pow(base,2**22,mod)
    res = [0]*2**n

    for i in range(n,0,-1):
        use_omega = pow(base,2**(22+i-n),mod)
        res = [0]*2**n
        size //= 2
        w = 1
        for j in range(0,L//2,size):
            for a in range(size):
                res[a+j] = (F[a+2*j] + w * F[a+size+2*j]) % mod
                t = (w * wj) % mod
                res[L//2+a+j] = (F[a+2*j] + t * F[a+size+2*j]) % mod
            w = (w * use_omega) % mod
        F = res

    return res

def ntt(f,L=0):
    l = len(f)
    if not L:
        L = 1<<((l-1).bit_length())
    while len(f)<L:
        f.append(0)
    f=f[:L]
    F = _ntt(f,L)
    return F

def intt(f,L=0):
    l = len(f)
    if not L:
        L = 1<<((l-1).bit_length())
    while len(f)<L:
        f.append(0)
    f=f[:L]
    F = _ntt(f,L,reverse=True)
    inv = pow(L,mod-2,mod)
    for i in range(L):
        F[i] *= inv
        F[i] %= mod
    return F

def convolve(f,g,limit):
    l = len(f)+len(g)-1
    L = 1<<((l-1).bit_length())

    F = ntt(f,L)
    G = ntt(g,L)

    H = [(F[i] * G[i]) % mod for i in range(L)]

    h = intt(H,L)

    return h[:limit]

N,Q = map(int,input().split())
A = list(map(int,input().split())) + [0] * N
r = list(map(int,input().split()))
query = [0 for i in range(N)] + [0] * N
for i in range(Q):
    query[N-1-r[i]] += 1
#print(query)
f = convolve(A,query,2*N)
ans = [0 for i in range(2*N)]
#print(f)
for i in range(2*N):
    ans[i] += f[i]
    if i+N<2*N:
        ans[i+N] += f[i]

for i in range(2*N):
    ans[i] %= mod

ans = ans[N-1:2*N-1]
print(*ans)
0