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 ...
随机推荐
- MC34063中文资料及应用实例(转)
源:http://blog.chinaunix.net/uid-26199686-id-3207838.html MC34063A(MC33063)芯片器件简介 该器件本身包含了DC/DC变换器所需要 ...
- sqlDataAdapter的FillSchema用法
摘自于网络:http://blog.csdn.net/bupt_zoucq/article/details/6653385 FillSchema是用来向DataTable中填入详细的元数据信息的,例如 ...
- 说说Core Animation
前言 本次分享将从以下方面进行展开: 曾被面试官问倒过的问题:层与视图的关系 CALayer类介绍及层与视图的关系 CAShapeLayer类介绍 UIBezierPath贝塞尔曲线讲解 CoreAn ...
- CSS实现三角形方法一--rotate+relative
方法说明:两个正方形,一个小的,一个大的,将大的正方向进行旋转,然后移动到小的正方形的合适位置,覆盖小正方形的一部分,使小正方形剩余部分为三角形,再把大正方形的背景色改为浏览器窗口的颜色. 用到知识: ...
- iOS学习基本常识
转发至:http://blog.sina.com.cn/s/blog_9266da3d010184i0.html 1. 了解main函数, UIApplication是初始化程序的核心,它接受4个参 ...
- away3d 汽车路线编辑器
2012年的时候,跟朋友去到一个公司,打算用away3d做一个赛车模拟养成游戏,后来由于种种原因,立项未成,由于朋友已经转行,自己也想对自己做过的事情有一些交代,所以将我负责的部分,赛道编辑器的源码公 ...
- SQL复习一(基础知识)
1.什么是sql SQL(structure query language)是结构化查询语言,它是对关系型数据库的操作语言.它可以应用到所有的数据库中,例如:MySQL.Oracle.SQL serv ...
- Arduino单片机使用和开发问题记录(转)
源:Arduino单片机使用和开发问题记录 1.将程序上传到板子时Arduino IDE提示“avrdude: stk500_getsync(): not in sync: resp=0x00” 网上 ...
- ie6,ie7兼容性总结
摘自: http://www.cnblogs.com/li0803/archive/2009/08/22/1552094.html 其实浏览器的不兼容,我们往往是各个浏览器对于一些标准的定义不一致导致 ...
- tableview的reloadData应注意
http://blog.csdn.net/ouyangtianhan/article/details/7835041 http://stackoverflow.com/questions/160715 ...