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 ...
随机推荐
- scrollView顶部空白
在iOS7之后,苹果会自动给导航控制器里面的所有UIScrollView顶部都会添加额外的滚动区域64.
- apache虚拟目录设置
<VirtualHost *:80> DocumentRoot "/xampp/htdocs/f" ServerName f.e-elitech.net</Vir ...
- Altera CYCLONE III FPGA BGA布线
最近在做altera FPGA BGA相关的布线工作,收集了一些资料,公开出来以供大家讨论. 首先是器件引脚,只有弄清楚器件各个引脚的功能才能够进行布线,下面的文档详细描述了每个引脚的功能. 各引脚功 ...
- CentOS 5.8 x64 安装TomCat
简单记录一下...虽然安装很简单... 首先下载配置安装 jdk http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u25-do ...
- 所有事件event集锦
'mousedown touchstart', 'mousemove touchmove', 'mouseup mouseleave touchend touchleave touchcancel', ...
- Android获取手机唯一码
大部分安卓手机都可以获取手机唯一码,但是有些手机的厂商却禁止了获取手机唯一码的权限,导致我们不能使用手机唯一码作为标识,但遇到一些必须要填的坑,我们也不能不填,所以使用以下方法来填坑,因此我们使用UU ...
- android gridview画分割线
dongyangzhang android gridview画分割线,如图: 1.先上图: 2.具体实现代码: public class LineGridView extends GridView { ...
- jqgrid的外观重绘
1.如果你想随时更改jqGrid的外观和列,可以先将jqGrid卸载掉再重新加载:$(grid).GridUnload(); $("#list_server_table").tr ...
- cygwin的安装,vi的使用,gcc,g++的使用(转)
源:cygwin的安装,vi的使用,gcc,g++的使用 Gcc的Makefile简单使用
- 微信小程序之----组件
1.view 把文档分割为独立的.不同的部分. view组件类似于html中的div标签,默认为块级元素,独占一行,可以通过设置display:inline-block改为行级元素. view.wxm ...