HDOJ 5475 An easy problem
题意:一个计算器,两种操作,乘上x,或者除掉之前的某个x,结果取模输出
分析:因为取模不支持除法,然后比赛时想到用逆元,结果发现MOD需要与b互质,结果一直苦苦寻找求逆元的其它方法。后来队友用暴力方法竟然水过,具体操作是记录每次乘的x,如果除的话,将对应的x 改为1,然后一个一个乘。当然正解应该用线段树,树的底部每个点表示每一次操作的x,pushup的是区间的乘积,如果是除把对应的x变为1,发现其实就是暴力的优化。。。。
/************************************************
* Author :Running_Time
* Created Time :2015/9/30 星期三 13:33:35
* File Name :H_ST.cpp
************************************************/ #include <cstdio>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std; #define lson l, mid, rt << 1
#define rson mid + 1, r, rt << 1 | 1
typedef long long ll;
const int N = 1e5 + 10;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const double EPS = 1e-8;
int M;
int pos[N];
struct ST {
int v[N<<2];
void push_up(int rt) {
v[rt] = (v[rt<<1] * 1ll * v[rt<<1|1]) % M;
}
void build(int l, int r, int rt) {
if (l == r) {
v[rt] = 1; return ;
}
int mid = (l + r) >> 1;
build (lson); build (rson);
push_up (rt);
}
void updata(int p, int c, int l, int r, int rt) {
if (l == r) {
v[rt] = c; return ;
}
int mid = (l + r) >> 1, ret = 1;
if (p <= mid) updata (p, c, lson);
else updata (p, c, rson);
push_up (rt);
}
}st; int main(void) {
int T, cas = 0; scanf ("%d", &T);
while (T--) {
int Q;
scanf ("%d%d", &Q, &M);
printf ("Case #%d:\n", ++cas); st.build (1, Q, 1);
int p = 1;
for (int op, x, i=1; i<=Q; ++i) {
scanf ("%d%d", &op, &x);
if (op == 1) {
st.updata (p, x, 1, Q, 1);
printf ("%d\n", st.v[1]);
pos[i] = p++;
}
else {
st.updata (pos[x], 1, 1, Q, 1);
printf ("%d\n", st.v[1]);
}
}
} return 0;
}
HDOJ 5475 An easy problem的更多相关文章
- hdu 5475 An easy problem(暴力 || 线段树区间单点更新)
http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...
- HDU 5475 An easy problem 线段树
An easy problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...
- HDOJ 2055 An easy problem
Problem Description we define f(A) = 1, f(a) = -1, f(B) = 2, f(b) = -2, - f(Z) = 26, f(z) = -26; Giv ...
- 2015上海网络赛 HDU 5475 An easy problem 线段树
题意就不说了 思路:线段树,维护区间乘积.2操作就将要除的点更新为1. #include<iostream> #include<cstdio> #include<cstr ...
- hud-5475 An easy problem(线段树)
http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...
- HDOJ(HDU) 2132 An easy problem
Problem Description We once did a lot of recursional problem . I think some of them is easy for you ...
- HDU 5475:An easy problem 这题也能用线段树做???
An easy problem Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) ...
- UVA-11991 Easy Problem from Rujia Liu?
Problem E Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for ...
- An easy problem
An easy problem Time Limit:3000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
随机推荐
- AOP和OOP的区别
AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术. AOP与OOP是面向不同领域的两种设计思想. ...
- 获取Wifi密码,不知道是不是真的
package com.example.wifipassword; import java.util.List; import android.app.Activity; import android ...
- HDU 6086 Rikka with String AC自动机 + DP
Rikka with String Problem Description As we know, Rikka is poor at math. Yuta is worrying about this ...
- Mac OS用vmvare安装多节点kubernetes
参考网址 https://kubernetes.io/docs/setup/ 1.安装vmvare 2.下载ubuntu镜像(可以不要界面,可以下载server版大约900M,否则下载desktop版 ...
- SpringMVC 之 Controller、Service层职责
Controller层 1.接收httpRequest/requestDTO数据 ,检查接收数据参数与格式. 2.传递参数至Service层并接收返回responseDTO数据. 3.包装respon ...
- UVAlive 6611 Alice's Print Service 二分
Alice is providing print service, while the pricing doesn't seem to be reasonable, so people using h ...
- POJ1651 Multiplication Puzzle —— DP 最优矩阵链乘 区间DP
题目链接:https://vjudge.net/problem/POJ-1651 Multiplication Puzzle Time Limit: 1000MS Memory Limit: 65 ...
- hdu 3746 Cyclic Nacklace(next数组求最小循环节)
题意:给出一串字符串,可以在字符串的开头的结尾添加字符,求添加最少的字符,使这个字符串是循环的(例如:abcab 在结尾添加1个c变为 abcabc 既可). 思路:求出最小循环节,看总长能不能整除. ...
- 书写优雅的shell脚本(三) - shell中exec解析
参考:<linux命令.编辑器与shell编程> <unix环境高级编程> exec和source都属于bash内部命令(builtins commands),在bash下输入 ...
- 【系列】 2-SAT
bzoj 1997 Planar 题目大意: 给一个存在曼哈顿回路的无向图,求该图是否为平面图 思路: 先把曼哈顿回路提出来,则剩下的边的两个端点若有$ABAB$的形式则这两条边必定一个在环外一个在环 ...