Description
The J language, as a programming language, was born in the 1990s ....
Studious Little H learned a new thing today--j language. Clearly, the background of the J language has been forgotten by little H, but little H still remembers interesting mathematical calculations in the J language-vector computing.
In the J language, vectors, scalars and operators are the basic elements, but in the impression of Little H, the most interesting part of J is its grammar, and the studious little H has also studied the grammar of J language and made simplification. In small H simplifies the syntax of J language, uses X to represent vectors, and n to represent the length of vector x.
The rules for simplifying the J language are as follows:
There are two operators in the operator, "+", "-", "*", while the corresponding operand can be two scalars, two vectors, or a scalar and a vector. (when two vectors are computed, respectively, for the corresponding bit, for example (2,3,4) = (2,6,12), when a scalar and a vector operation, as a scalar and a vector of each bit operation, for example (three-in-one) * 5 = (5,10,15)
Operators also have unary operators, including the negative operator "-" and the square operator "*:" whose operands can be scalar and vector. (The vector takes the square operator as a square for each bit, for example *:(1, 2, 3) = (1, 4, 9), and the scalar is squared in mathematical sense, e.g. *:4 = 16)
The sum operator "+/", which can only be used for vectors, can sum vectors as scalars, such as +/(6)
The J operator is in the right-to-left order of operations, and the precedence is ignored, and the part that needs to be evaluated will be prioritized in parentheses (allowing nested parentheses).
The J Language of small H reduction has a limit--the limit of the highest order, so we define the order of a number of expressions:
The order of the scalar (number, ' N ', the result of the sum operator "+/") is 0, the complexity of ' X ' is 1, the order of addition and subtraction is the maximum of the order of its operands, and the order of the multiplication is the sum of the order of its operands;
The order of the unary square is twice times the order of its operands.
For example, the order of the expression "(3-+/*:*: x)-x**:x" is 3, and its sub-expression "*:*: X" is the order of 4.
Little H found an expression that had previously written a simplified version of the J language, but don't forget that little H just likes to think rather than calculate. Now, Little H would like to ask you to help him calculate the answer to the given expression, and the final answer modulo 10^9 (must ensure that the result is negative, that is, if the remainder is minus to add 10^9), of course, small h also clearly remember that he wrote the expression in the process of the order will not exceed 10.
Main
Give you a formula and a vector, perform the operation according to the rules, and ask for the result.
Analysis
Considering that the order is smaller, a polynomial can be represented by the coefficients and the number of times. The number of times (0~10) of the X-main element is recorded and its coefficients are set to p.
Because there are many different constants and polynomial, ways to classify them as a class, so, the constant term is represented as {x,0,0,0,0,....}, the polynomial is represented as {x,x,x,x,x,x ...}, in fact X represents any number.
There may be constant terms and polynomial operations, considering a similar calculation method between different types of numbers. You can have a 0-time square-term coefficient as a constant term for each position of the vector, so
Solution
Preprocessing the x^k vectors for each point
[JZOJ3588] "Zhongshan Select 2014" J Language (expression parsing + stack)