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+86

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

((((24)+2)3)+8)6=6048.

As for x=3, it will output

((((34)+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+25+86.

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{+,,^}0x<29393.
 

 

Input
The first line contains an integer T(T10), denoting the number of test cases. It is guaranteed that 1n,m50000.

For each test case, the first line contains two numbers n,mn 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.
 

 

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(线段树,中国剩余定理)的主要内容,如果未能解决你的问题,请参考以下文章

hdu-4819-线段树套线段树

hdu 4614 线段树 二分

hdu6464 线段树

二维线段树(hdu1823)

HDU 4027(线段树)

(c) hdu1394* (求逆序对数)(线段树)