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

One day, a useless calculator was being built by Kuros. Let's assume that number X is showed on the screen of calculator. At first, X = 1. This calculator only supports two types of operation.
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

The first line is an integer T(1≤T≤10), indicating the number of test cases.
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

For each test case, the first line, please output "Case #x:" and x is the id of the test cases starting from 1.
Then Q lines follow, each line please output an answer showed by the calculator.
 

Sample Input

1
10 1000000000
1 2
2 1
1 2
1 10
2 3
2 4
1 6
1 7
1 12
2 7
 

Sample Output

Case #1:
2
1
2
20
10
1
6
42
504
84
 

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的更多相关文章

  1. hdu-5475 An easy problem---线段树+取模

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5475 题目大意: 给X赋初值1,然后给Q个操作,每个操作对应一个整数M: 如果操作是1则将X乘以对应 ...

  2. HDU5475(线段树)

    An easy problem Time Limit: 8000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  3. ACM学习历程—HDU5475 An easy problem(线段树)(2015上海网赛08题)

    Problem Description One day, a useless calculator was being built by Kuros. Let's assume that number ...

  4. hdu5475(线段树单点修改,统计区间乘积)

    题目意思: 给定a*b*c*d*e*f*....,可以在某一步去掉前面的一个因子,每次回答乘积. #include <cstdio> #include <cstring> #i ...

随机推荐

  1. Subsequences Summing to Sevens

    Subsequences Summing to Sevens 题目描述 Farmer John's N cows are standing in a row, as they have a tende ...

  2. 学习Redis从这里开始

    本文主要内容 Redis与其他软件的相同之处和不同之处 Redis的用法 使用Python示例代码与Redis进行简单的互动 使用Redis解决实际问题 Redis是一个远程内存数据库,它不仅性能强劲 ...

  3. Spring mvc 返回json格式 - 龙企阁 - 博客频道 - CSDN.NET

    第一次使用spring mvc ,在此也算是记录一下以防忘记,希望有经验的朋友指出不足的地方 一.使用maven管理jar. <dependency> <groupId>org ...

  4. POJ 1696 Space Ant

    极角排序 每次选择一个最外围的没选过的点,选择的时候需要利用极角排序进行选择 #include<cstdio> #include<cstring> #include<ve ...

  5. java工程师联通XX面试题目

    什么是“长连接”和“短连接”? 所谓短连接指建立SOCKET连接后发送后接收完数据后马上断开连接,一般银行都使用短连接解释2长连接就是指在基于tcp的通讯中,一直保持连接,不管当前是否发送或者接收数据 ...

  6. 为CKEditor开发插入代码的插件 已提供下载

    http://www.cnblogs.com/moozi/archive/2010/01/06/1640034.html

  7. iOS学习笔记1--在xcode6以上的版本中不使用storyboard以及部分控件使用

    首先建立一个iOS新工程,删除工程自动建立的main.storyboard以及xib文件,并且在info.plist上删除这两个选项 然后在项目配置中将maninterface设置为空,将launch ...

  8. 菊花加载第三方--MBprogressHUD

    上次说到了网络请求AFN,那么我们在网络请求的时候,等待期间,为了让用户不认为是卡死或程序出错,一般都会放一个菊花加载,系统有一个菊花加载类叫UIProgressHUD.但是我今天要说的是一个替代它的 ...

  9. cocos2d-x---开篇介绍

    关于cocos2d-x这一游戏引擎,现在受到了手机游戏开发者的青睐.其实cocos2d一开始是由于cocos2d-iphone的成功,然后带动各类开源项目越来越火.由苹果独家的Objective-C到 ...

  10. 转载自前端开发:CSS设置滚动条样式

    浏览器默认的滚动条样子太过屌丝了,得自己动手整整.记得IE浏览器有几个设置滚条的样式,不过比较鸡肋,只能设置颜色之类的,而且webkit下面也不支持.无意间看到网易邮箱的滚动条样子很好看,一开始以为是 ...