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 ...
随机推荐
- LeetCode(21)题解:Merge Two Sorted Lists
https://leetcode.com/problems/merge-two-sorted-lists/ Merge two sorted linked lists and return it as ...
- vue 单页面(SPA) history模式调用微信jssdk 跳转后偶尔 "invalid signature"错误解决方案
项目背景 vue-cli生成的单页面项目,router使用history模式.产品会在公众号内使用,需要添加微信JSSDK,做分享相关配置. 遇到的问题 相关配置与JS接口安全域名都已经ok,发布后, ...
- YTU 2578: 分数减法——结构体
2578: 分数减法--结构体 时间限制: 1 Sec 内存限制: 128 MB 提交: 522 解决: 399 题目描述 分数可以看成是由字符'/'分割两个整数构成,可以用结构体类型表示.请用结 ...
- NOSQL安全攻击
摘自:http://www.infoq.com/cn/articles/nosql-injections-analysis JSON查询以及数据格式 PHP编码数组为原生JSON.嗯,数组示例如下: ...
- 命令行 sql 将结果导出到文件
1. into outfile filename; Mysql查询结果导出为Excel的几种方法 mysql> use world; # 使用 mysql 自带的 world 数据库 mysql ...
- macbook pro 下eclipse配置svn插件
eclipse中最常使用的SVN插件是subclipse,先到subclipse官网:http://subclipse.tigris.org下载该插件. 如上图,点击“Download and I ...
- Linux的终端类型
终端是一个很重要的外设,用过终端设备的人都知道如果设备类型不对就会有乱字符,也可用仿真终端软件如netterm试验一下,Linux的终端信息放在 /usr/share/terminfo下,在这个目录的 ...
- 压缩&&解压
压缩与解压缩: ############################################################# tar xvf wordpress.tar ## ...
- VPS 安全措施(CentOS 6)
新到手一台VPS,要做的第一件事大概是做好安全措施. 下面针对CentOS 6随便写点,我目前做的几步是: 修改root密码 SSH-key登录 配置iptable 安装fail2ban 1.修改ro ...
- Mac 下的截图技巧
最近想制作GIF图片,截图后,发现没有截出鼠标小效果,自己就查阅了一下资料,总结了不少的截图技巧,这里写下来,权当笔记,方便今后检索,方便别人共享. 方法一: 下载 QQ,在QQ的皮娜好设置里面设置截 ...