#P7812. Expression
Expression
Expression
Problem Description
You are given an expression string of length consisting of variables and . The symbol is used to denote the variable . It is assumed that there are different variables in total. It guarantees that each variable appears only once. So the expression string can be regarded as a multivariate function . We denote:
$$g(t)=\sum_{1 \le i_1,i_2,\cdots, i_t \le n} h(i_1,i_2,\cdots,i_t; t) $$$$h(i_1,i_2,\cdots,i_t; t)= \frac{\partial^{t} }{\partial x_{i_1} \partial x_{i_2} \cdots \partial x_{i_t}} f $$For the given value of . You have the following two tasks. 1.Calculate 2.For the following m queries, you are given , print the answer Since they may be too large, print all of them . If you knew little about higher-order partial and mixed derivatives, you can refer to https://en.wikipedia.org/wiki/Partial_derivative#Notation.
Input
The first line contains an integer denoting the number of test cases. For each test case: The first line contains two integers and --- represents the length of expression string and represents the number of variables. The second line contains one string consisting of variables and . The third line contains integers, which are the values of . The fourth line contains a integer denoting the number of query. The -th of the following lines denotes the -th query, which contains integers . It guarantees that: $T \in [1,20],\space x_i \in [-10^8,10^8],\space L \in [1,10^5],\space\sum L \in [1,3 \times 10^5].$ $n \in [1,10^4],\space\sum n \in [1,3 \times 10^4],\space\sum t \in [1,10^7],\space\sum m \in [0,8 \times 10^5].$
Output
For each test, print lines. The first line outputs integers: the -th integer means . For the -th of the following lines, print the answer of -th query
Sample Input
1
11 3
[1]*[2]*[3]
1 2 3
3
1 1
2 1 2
3 1 2 3
Sample Output
6 11 12 6 0 0
6
3
1
Source
2020 Multi-University Training Contest 5