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 ...
随机推荐
- ural1019 Line Painting
Line Painting Time limit: 2.0 secondMemory limit: 64 MB The segment of numerical axis from 0 to 109 ...
- [zoj解题] 1203
#include <stdio.h> #include <stdlib.h> #include <math.h> #define MAXN 100 #define ...
- 常见的Js
//根据单独的值切换所有复选框 $("input[type='checkbox']").prop("checked", function( i, val ) { ...
- (简单) POJ 3074 Sudoku, DLX+精确覆盖。
Description In the game of Sudoku, you are given a large 9 × 9 grid divided into smaller 3 × 3 subgr ...
- html5 canvas 五子棋游戏
<!doctype html> <html> <head> <meta charset="utf-8"> <title> ...
- ICE第四篇-----python版本
ice文件: module Modipplace { interface Ipplace{ string iptoplace(string s); }; }; ...
- 12、手把手教你Extjs5(十二)执行菜单命令在tabPanel中显示模块
上面设计好了一个模块的主界面,下面通过菜单命令的执行来把这个模块加入到主界面当中.在MainModule.js中有一个函数,生成了当前的菜单数据: // 根据data.systemMenu生成菜单条和 ...
- Android线程之异步消息处理机制(一)
Android不允许在子线程中进行UI操作,但是有些时候,我们必须在子线程里去执行一些耗时任务,然后根据任务的执行结果来更新相应的UI控件.对于这种情况,Android提供了一套异步消息处理机制,完美 ...
- CSS如何让DIV的宽度随内容的变化
[css]CSS如何让DIV的宽度随内容的变化 让div根据内容改变大小 div{ width:auto; display:inline-block !important; display:inlin ...
- Git Flow——Git团队协作最佳实践
规范的Git使用 Git是一个很好的版本管理工具,不过相比于传统的版本管理工具,学习成本比较高. 实际开发中,如果团队成员比较多,开发迭代频繁,对Git的应用比较混乱,会产生很多不必要的冲突或者代码丢 ...