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.

 
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''.

 
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(线段树,中国剩余定理¥)的更多相关文章

  1. HDU 5238 Calculator 线段树 中国剩余定理

    题意: 给一个计算器,有一系列计算步骤,只有加,乘,幂三种运算. 有一种查询操作:查询初始值为\(x\)的时候,最终运算结果模\(29393\)的值. 有一种修改操作:可以修改第\(p\)个运算的运算 ...

  2. hdu 4031 attack 线段树区间更新

    Attack Time Limit: 5000/3000 MS (Java/Others)    Memory Limit: 65768/65768 K (Java/Others)Total Subm ...

  3. hdu 4288 离线线段树+间隔求和

    Coder Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  4. hdu 3016 dp+线段树

    Man Down Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total S ...

  5. HDU 5877 dfs+ 线段树(或+树状树组)

    1.HDU 5877  Weak Pair 2.总结:有多种做法,这里写了dfs+线段树(或+树状树组),还可用主席树或平衡树,但还不会这两个 3.思路:利用dfs遍历子节点,同时对于每个子节点au, ...

  6. HDU 3308 LCIS (线段树区间合并)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3308 题目很好懂,就是单点更新,然后求区间的最长上升子序列. 线段树区间合并问题,注意合并的条件是a[ ...

  7. HDU 2795 Billboard (线段树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2795 题目大意:有一块h*w的矩形广告板,要往上面贴广告;   然后给n个1*wi的广告,要求把广告贴 ...

  8. hdu 5480 Conturbatio 线段树 单点更新,区间查询最小值

    Conturbatio Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=54 ...

  9. hdu 1828 Picture(线段树 || 普通hash标记)

    http://acm.hdu.edu.cn/showproblem.php?pid=1828 Picture Time Limit: 6000/2000 MS (Java/Others)    Mem ...

  10. hdu 4747【线段树-成段更新】.cpp

    题意: 给出一个有n个数的数列,并定义mex(l, r)表示数列中第l个元素到第r个元素中第一个没有出现的最小非负整数. 求出这个数列中所有mex的值. 思路: 可以看出对于一个数列,mex(r, r ...

随机推荐

  1. MySQL 第五天

    回顾 连接查询: 多张表连接到一起, 不管记录数如何,字段数一定会增加. 分类: 内连接,外连接,自然连接和交叉连接 交叉连接: cross join(笛卡尔积) 内连接: inner join, 左 ...

  2. 201703 ABAP面试题002

    转自: ABAP 面试问题及答案(一):数据库更新及更改 SAP Standard (转) 问题一:锁对象(Lock Object)和 FM(Function Module)激活锁定对象时,产生的 F ...

  3. 做测试时,启动SpringBoot出现警告,在ClassPath中一个类多次出现

    Found multiple occurrences of org.json.JSONObject on the class path: jar:file:/C:/Users/niaomingjian ...

  4. 曾经跳过的坑------JS中对象与结构体的声明和调用

    直接上代码 正确的写法 //同一个ready方法中var viewModel = { // self.projectCode = PROJECT_CODE; BOOKEDCOUNT : 5, TOTA ...

  5. 系统架构师考试——程序计数器 PC, 指令寄存器IR、状态寄存器SR、通用寄存器GR

    ● 计算机执行程序时,在一个指令周期的过程中,为了能够从内存中读指令操作码,首先是将__(9)___的内容送到地址总线上. (9)A.程序计数器PC    B.指令寄存器IR C.状态寄存器SR    ...

  6. HackerRank - fibonacci-modified 【大数】

    思路 用PYTHON 或 JAVA 干掉 AC代码 a, b, n = map(int, input().split()) for i in range (2, n, 1) : temp = b b ...

  7. Loadrunder之脚本篇——检查点

    VuGen判断脚本是否执行成功是根据服务器返回的状态来确定的,如果服务器返回的是HTTP状态为200 OK,那么VuGen就认为脚本正确地运行了,并且是运行通过的.而大多数系统出错时是不会返回错误页面 ...

  8. 每天一个Linux命令(59)wget命令

        wget命令用来从指定的URL下载文件.     (1)用法:     用法:  wget  [参数]  [URL]     (2)功能:     功能:  wget命令用来从指定的URL下载 ...

  9. InnoDB存储引擎内存缓冲池管理技术——LRU List、Free List、Flush List

    InnoDB是事务安全的MySQL存储引擎,野山谷OLTP应用中核心表的首选存储引擎.他是基于表的存储引擎,而不是基于数据库的.其特点是行锁设计.支持MVCC.支持外键.提供一致性非锁定读,同时被设计 ...

  10. dfs的返回条件

    用到dfs时要注意设置函数的返回条件,否则会导致一直wa!!!!!