結果

問題 No.1172 Add Recursive Sequence
ユーザー SalmonizeSalmonize
提出日時 2020-08-14 23:06:20
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 2,401 bytes
コンパイル時間 366 ms
コンパイル使用メモリ 82,184 KB
実行使用メモリ 113,744 KB
最終ジャッジ日時 2024-10-10 16:33:33
合計ジャッジ時間 9,513 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
52,352 KB
testcase_01 AC 41 ms
52,480 KB
testcase_02 AC 40 ms
52,480 KB
testcase_03 AC 42 ms
52,224 KB
testcase_04 AC 40 ms
52,736 KB
testcase_05 AC 41 ms
52,480 KB
testcase_06 AC 145 ms
77,568 KB
testcase_07 AC 127 ms
77,568 KB
testcase_08 AC 107 ms
77,440 KB
testcase_09 AC 110 ms
77,056 KB
testcase_10 AC 257 ms
82,356 KB
testcase_11 AC 351 ms
83,720 KB
testcase_12 AC 137 ms
78,080 KB
testcase_13 AC 143 ms
78,208 KB
testcase_14 AC 941 ms
113,744 KB
testcase_15 AC 322 ms
86,196 KB
testcase_16 TLE -
testcase_17 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

readline = sys.stdin.buffer.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prn = lambda x: print(*x, sep='\n')

def Kitamasa(C, X, k, e0=0, e1=1, mod=10**9+7):
	'''
	0-indexed
	calc X[k]
	'''
	n = len(X)

	def _plus1(g):
	    ret = [(g[i-1] + g[-1] * C[i]) % mod for i in range(n)]
	    ret[0] = g[-1] * C[0] % mod
	    return ret

	def _mult2(g):
	    ret = [e0]*(2 * n - 1)
	    for i in range(n):
		    for j in range(n):
		        ret[i + j] = (ret[i + j] + g[i] * g[j]) % mod
	    for i in range(2*n-2, n-1, -1):
		    for j in range(n):
		        ret[i + j - n] = (ret[i + j - n] + ret[i] * C[j]) % mod
	    return ret[:n]

	g = [e0]*n
	g[0] = e1
	t = k.bit_length()
	for i in range(t-1, -1, -1):
		g = _mult2(g)
		if k & (1<<i):
			g = _plus1(g)

	ans = e0
	for i in range(n):
		ans = (ans + g[i] * X[i]) % mod

	return ans


def solve():
    k, n, m = nm()
    a = nl()
    c = nl()[::-1]
    f = [0]*n
    g = [list() for _ in range(n+1)]
    d = dict()
    mod = 10**9 + 7
    for _ in range(m):
        l, r = nm()
        f[l] += 1
        g[r].append(r-l)

    def plus1(g):
	    ret = [(g[i-1] + g[-1] * c[i]) % mod for i in range(k)]
	    ret[0] = g[-1] * c[0] % mod
	    return ret

    def mult2(g):
	    ret = [0]*(2 * k - 1)
	    for i in range(k):
		    for j in range(k):
		        ret[i + j] = (ret[i + j] + g[i] * g[j]) % mod
	    for i in range(2 * k - 2, k - 1, -1):
		    for j in range(k):
		        ret[i + j - k] = (ret[i + j - k] + ret[i] * c[j]) % mod
	    return ret[:k]

    def search(x):
        if x in d:
            return d[x]
        if x < k:
            ret = [0] * k
            ret[x] = 1
            d[x] = ret
        elif x & 1:
            d[x] = plus1(search(x-1))
        else:
            d[x] = mult2(search(x>>1))
        return d[x]

    cur = [0] * k
    for i in range(n):
        # print(i, f[i], g[i])
        cur = plus1(cur)
        cur[0] += f[i]
        for x in g[i]:
            neg = search(x)
            for j in range(k):
                cur[j] -= neg[j]
        # print(cur, i, f[i], g[i])
        print(sum(cur[j]*a[j] for j in range(k)) % mod)
    # cur = [1, 0]
    # for i in range(10):
    #     cur = plus1(cur)
    #     print(cur, search(i+1))
    return

solve()
0