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. opencv3计算机视觉+Python(四)

    使用分水岭和GrabCut算法进行物体分割 用GrabCut算法进行图像分割 在OpenCV中,实现了grabcut分割算法,该算法可以方便的分割出前景图像,操作简单,而且分割的效果很好.算法的原理参 ...

  2. Java的变量命名

    Java的变量命名 1.首字母是英文字母.$和下划线,由字母.数字和下划线组成.  [很常规] 2.变量的命名遵循见名知义的原则.  [很重要,比如名字就用 name ,而不是用a.b.c这样的命名, ...

  3. 剑指offer 面试56题

    面试56题: 题目:数组中数字出现的次数 题:一个整型数组里除了两个数字之外,其他的数字都出现了两次.请写程序找出这两个只出现一次的数字. 解题思路: 方法一:异或运算,详见<剑指offer&g ...

  4. MyEclipse工具栏的隐藏与显示及自定义

    Myeclipse的工具栏 1.隐藏 工具栏---->右键---->hide toolbar 2.显示     window ----> show toolbar 3.自定义     ...

  5. 前端基础之JavaScript_(4)_js的作用域

    js作用域 作用域就是变量与函数的可访问范围,即作用域控制着变量与函数的可见性和生命周期.在JavaScript中,变量的作用域有全局作用域和局部作用域两种. js的作用域 1. 全局作用域(Glob ...

  6. 第二篇 Python图片处理模块PIL(pillow)

    本篇包含:16.Point    17.Putalpha    18.Putdata    19.Putpalette    20.Putpixel      21.Quantize     22.R ...

  7. springboot-整合freemarker

    freemarker是一个页面模板引擎.用springboot整合freemarker的方式如以下步骤: 1.在创建springboot的项目的时候,选择freemarker的组件,或者自己手动在ma ...

  8. Golang 连接Kafka

    Kafka介绍 Kafka是Apache软件基金会开发的一个开源流处理平台,由Java和Scala编写:Kafka是一种高吞吐.分布式.基于订阅发布的消息系统. Kafka名称解释 Producer: ...

  9. Bootstrap3组件--2

    目录 1. 分页 2. 标签 3. 徽章 4. 巨幕 5. 页头 6. 缩略图 7. 警告框 8. 进度条 9. 列表组 10. 面板 11.Well 1. 分页 <!doctype html& ...

  10. MongoDB快速入门(三)- 集合

    创建集合 MongoDB 的 db.createCollection(name, options) 用于创建集合. 在命令中, name 是要创建集合的名称. Options 是一个文档,用于指定集合 ...