HDU5475
An easy problem
Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 1697 Accepted Submission(s): 760
Problem Description
1. multiply X with a number.
2. divide X with a number which was multiplied before.
After each operation, please output the number X modulo M.
Input
For each test case, the first line are two integers Q and M. Q is the number of operations and M is described above. (1≤Q≤105,1≤M≤109)
The next Q lines, each line starts with an integer x indicating the type of operation.
if x is 1, an integer y is given, indicating the number to multiply. (0<y≤109)
if x is 2, an integer n is given. The calculator will divide the number which is multiplied in the nth operation. (the nth operation must be a type 1 operation.)
It's guaranteed that in type 2 operation, there won't be two same n.
Output
Then Q lines follow, each line please output an answer showed by the calculator.
Sample Input
Sample Output
Source
//2016.9.12
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 100005 using namespace std; int nu[N], book[N]; int main()
{
long long ans;
int T, kase = , q, mod, op;
scanf("%d", &T);
while(T--)
{
ans = ;
memset(book, true, sizeof(book));
printf("Case #%d:\n", ++kase);
scanf("%d%d", &q, &mod);
for(int i = ; i <= q; i++)
{
scanf("%d%d", &op, &nu[i]);
if(op == )
{
ans *= nu[i];
ans %= mod;
}
else
{
book[nu[i]] = false;
book[i] = false;
ans = ;
for(int j = ; j < i; j++)
{
if(book[j])ans = (ans*nu[j])%mod;
}
}
printf("%lld\n", ans);
}
} return ;
}
HDU5475的更多相关文章
- hdu-5475 An easy problem---线段树+取模
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5475 题目大意: 给X赋初值1,然后给Q个操作,每个操作对应一个整数M: 如果操作是1则将X乘以对应 ...
- HDU5475(线段树)
An easy problem Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- ACM学习历程—HDU5475 An easy problem(线段树)(2015上海网赛08题)
Problem Description One day, a useless calculator was being built by Kuros. Let's assume that number ...
- hdu5475(线段树单点修改,统计区间乘积)
题目意思: 给定a*b*c*d*e*f*....,可以在某一步去掉前面的一个因子,每次回答乘积. #include <cstdio> #include <cstring> #i ...
随机推荐
- javascript的 replace() 方法的使用讲解
String.prototype.replace() The replace() method returns a new string with some or all matches of a p ...
- BP神经网络的Java实现
http://fantasticinblur.iteye.com/blog/1465497
- hibernate--ID生成策略--annotation
annotation: @GeneratedValue a) 自定义ID b)auto: 对mysql默认使用auto_increment, 对oracle使用hibernate_sequence c ...
- 彻底领悟javascript中的this
this是Javascript语言的一个关键字. 它代表函数运行时,自动生成的一个内部对象,只能在函数内部使用.比如, function test() { this.x = 1; } 随着函数使用场合 ...
- Spring自学教程-声明式事务处理(六)
Spring事务处理分两种: 一.编程式事务:在程序中控制事务开始,执行和提交: 1.1 使用TransactionTemplate, 使用回调函数执行事务,不需要显示开始事务,不需要显示提交事务,但 ...
- iOS友盟三方登陆
Umeng三方登陆个人总结 Demo地址:https://github.com/haozheMa/UmengThirdLoginDemo这里仅以微信.QQ和新浪微博作为例子首先根据官方文档 导入以下依 ...
- OSD的主要实现方法和类型(转)
源:OSD的主要实现方法和类型 目前有两种主要的OSD实现方法:外部OSD发生器与视频处理器间的叠加合成;视频处理器内部 支持OSD,直接在视频缓存内部叠加OSD信息. 外部OSD发生器与视频处理器间 ...
- NPOI使用Datatable导出到Excel
首先要引用dll 下载地址:http://pan.baidu.com/s/1dFr2m 引入命名空间: using NPOI.HSSF.UserModel;using NPOI.SS.UserMode ...
- iOS调用相机,相册,上传头像
一.新建工程 二.拖控件,创建映射 三.在.h中加入delegate @interface ViewController : UIViewController 复制代码 四.实现按钮事件 -(IBAc ...
- NLPIR中文分词器的使用
一.普通java项目 (1)添加项目jar包 File -> Project Structure Libarries 添加jar包jna-4.0.0.jar (2)将Data文件夹复制到 ...