QOJ.ac

QOJ

Type: Editorial

Status: Open

Posted by: jiangly

Posted at: 2026-02-19 13:12:21

Last updated: 2026-02-19 13:12:26

Back to Problem

题解

可以将式子的求值用矩阵乘法表示:当前的表达式形如 $A+B\cdot C$,可以用矩阵表示 $A,B\cdot C,B,1$ 之间的转移。对于所有情况求和只需将每个位置的矩阵求和之后乘起来即可。时间复杂度 $O(n)$。

Comments

No comments yet.