結果
問題 | No.510 二次漸化式 |
ユーザー | maspy |
提出日時 | 2020-04-03 00:52:06 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,185 bytes |
コンパイル時間 | 193 ms |
コンパイル使用メモリ | 81,920 KB |
実行使用メモリ | 152,448 KB |
最終ジャッジ日時 | 2024-06-28 15:28:51 |
合計ジャッジ時間 | 20,451 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 41 ms
52,096 KB |
testcase_01 | AC | 43 ms
52,736 KB |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | WA | - |
testcase_31 | AC | 772 ms
152,448 KB |
testcase_32 | AC | 791 ms
152,192 KB |
testcase_33 | WA | - |
testcase_34 | AC | 461 ms
83,200 KB |
testcase_35 | AC | 423 ms
83,328 KB |
ソースコード
#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines MOD = 10 ** 9 + 7 class SegTree: """ segment tree with point modification and range product access. """ data_unit = (1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1) @classmethod def data_f(cls, A, B): C = [0] * 16 for i in range(4): for j in range(i, 4): for k in range(j, 4): C[4 * i + k] += B[4 * i + j] * A[4 * j + k] return tuple(x % MOD for x in C) def __init__(self, N): self.N = N self.data = [self.data_unit] * (N + N) def build(self, raw_data): data = self.data f = self.data_f N = self.N data[N:] = raw_data[:] for i in range(N - 1, 0, -1): data[i] = f(data[i << 1], data[i << 1 | 1]) def set_val(self, i, x): data = self.data f = self.data_f i += self.N data[i] = x while i > 1: i >>= 1 data[i] = f(data[i << 1], data[i << 1 | 1]) def fold(self, L, R): """ compute for [L, R) """ vL = vR = self.data_unit data = self.data f = self.data_f L += self.N R += self.N while L < R: if L & 1: vL = f(vL, data[L]) L += 1 if R & 1: R -= 1 vR = f(data[R], vR) L >>= 1 R >>= 1 return f(vL, vR) N = int(readline()) X = [0] * N Y = [0] * N Q = int(readline()) seg = SegTree(N) def mat(x, y): return (1, x, 0, 0, 0, y * y, 2 * y, 1, 0, 0, y, 1, 0, 0, 0, 1) for query in readlines(): if query.startswith(b'a'): i = int(query[2:]) if i == 0: print(1) else: A = seg.fold(0, i) print(sum(A[:4]) % MOD) elif query.startswith(b'x'): i, v = map(int, query[2:].split()) X[i] = v seg.set_val(i, mat(v, Y[i])) elif query.startswith(b'y'): i, v = map(int, query[2:].split()) Y[i] = v seg.set_val(i, mat(X[i], v))