hdu 5238 Calculator(线段树,中国剩余定理)
Posted gongpixin
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了hdu 5238 Calculator(线段树,中国剩余定理)相关的知识,希望对你有一定的参考价值。
Calculator
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 521 Accepted Submission(s): 170
Problem Description
Sakura has invented a new kind of calculator that can evaluate expressions. This calculator maintains a serial of operators and numbers inside. All these numbers and operators form an ordered table. For example
∗4+2^3+8∗6
is a possible table. The calculator also supports the following two operations.
1. 1 x.
This corresponds to the evaluation operation. For instance, if x=2, together with the table being the one described above, the calculator will output
((((2∗4)+2)3)+8)∗6=6048.
As for x=3, it will output
((((3∗4)+2)3)+8)∗6=16512.
2. 2 p cx.
This corresponds to the modification operation. The calculator will change the p-th term in the expression to cx. Here c denotes an operator while x denotes a number.
For example, if p=3 and cx=∗5, the expression will become
∗4+2∗5+8∗6.
Now you are asked to implement this calculator. However, for technical reasons, you should just output the result modulo 29393. It is guaranteed that, in all terms appeared in the input data, c∈{+,∗,^}, 0≤x<29393.
∗4+2^3+8∗6
is a possible table. The calculator also supports the following two operations.
1. 1 x.
This corresponds to the evaluation operation. For instance, if x=2, together with the table being the one described above, the calculator will output
((((2∗4)+2)3)+8)∗6=6048.
As for x=3, it will output
((((3∗4)+2)3)+8)∗6=16512.
2. 2 p cx.
This corresponds to the modification operation. The calculator will change the p-th term in the expression to cx. Here c denotes an operator while x denotes a number.
For example, if p=3 and cx=∗5, the expression will become
∗4+2∗5+8∗6.
Now you are asked to implement this calculator. However, for technical reasons, you should just output the result modulo 29393. It is guaranteed that, in all terms appeared in the input data, c∈{+,∗,^}, 0≤x<29393.
Input
The first line contains an integer T(T≤10), denoting the number of test cases. It is guaranteed that 1≤n,m≤50000.
For each test case, the first line contains two numbers n,m. n denotes the number of terms in the expression, m denotes the number of operations.
In the following n lines, each line contains a term in style of cx, denotes each term in the initial table.
In the following m lines, each line contains an operation. It must in style of ‘‘1x‘‘ or ‘‘2pcx‘‘.
For each test case, the first line contains two numbers n,m. n denotes the number of terms in the expression, m denotes the number of operations.
In the following n lines, each line contains a term in style of cx, denotes each term in the initial table.
In the following m lines, each line contains an operation. It must in style of ‘‘1x‘‘ or ‘‘2pcx‘‘.
Output
For each test case, output Case #t: in a single line to represent the t-th case.
Then in each test case, output the result modulo 29393 for each evaluation operation.
Then in each test case, output the result modulo 29393 for each evaluation operation.
Sample Input
2
5 4
*4
+2
^3
+8
*6
1 2
1 3
2 3 *5
1 3
4 3
*4
^4
+4
*10
1 1
2 3 ^4
1 1
Sample Output
Case #1:
6048
16512
468
Case #2:
2600
4107
P
Source
以上是关于hdu 5238 Calculator(线段树,中国剩余定理)的主要内容,如果未能解决你的问题,请参考以下文章