题目传送门

题意:一个计算器,两种操作,乘上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的更多相关文章

  1. hdu 5475 An easy problem(暴力 || 线段树区间单点更新)

    http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...

  2. HDU 5475 An easy problem 线段树

    An easy problem Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...

  3. 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 ...

  4. 2015上海网络赛 HDU 5475 An easy problem 线段树

    题意就不说了 思路:线段树,维护区间乘积.2操作就将要除的点更新为1. #include<iostream> #include<cstdio> #include<cstr ...

  5. hud-5475 An easy problem(线段树)

    http://acm.hdu.edu.cn/showproblem.php?pid=5475 An easy problem Time Limit: 8000/5000 MS (Java/Others ...

  6. 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 ...

  7. HDU 5475:An easy problem 这题也能用线段树做???

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

  8. UVA-11991 Easy Problem from Rujia Liu?

    Problem E Easy Problem from Rujia Liu? Though Rujia Liu usually sets hard problems for contests (for ...

  9. An easy problem

    An easy problem Time Limit:3000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

随机推荐

  1. error C2065: 'CArchiveStream' : undeclared identifier

    release:模式下 问题: 在导入JPEG文件时要使用到  CArchiveStream类  但是编译的时候会出现  'CArchiveStream'   :   undeclared   ide ...

  2. python day - 17 面向对象的 类空间 和 组合

    1. 类命名空间 在类的代码中,当python 解释器在 运行的那一刻.就会在内存中开辟一个类空间,在类的空间中会加载静态变量,以及类方法的内存地址. 当类名+()(也就是实例化过程中),内存中会再次 ...

  3. Lily HBase Indexer同步HBase二级索引到Solr丢失数据的问题分析

    一.问题描述二.分析步骤2.1 查看日志2.2 修改Solr的硬提交2.3 寻求StackOverFlow帮助2.4 修改了read-row="never"后,丢失部分字段2.5 ...

  4. redis04-----Hash 哈希数据类型相关命令

    Hash 哈希数据类型相关命令 hset key field value 这里的域就是键值对的键. 作用: 把key中 filed域的值设为value 注:如果没有field域,直接添加,如果有,则覆 ...

  5. js运行机制及异步编程(一)

    相信大家在面试的过程中经常遇到查看执行顺序的问题,如setTimeout,promise,async await等等,各种组合,是不是感觉头都要晕掉了,其实这些问题最终还是考察大家对js的运行机制是否 ...

  6. HDU3652 B-number —— 数位DP

    题目链接:https://vjudge.net/problem/HDU-3652 B-number Time Limit: 2000/1000 MS (Java/Others)    Memory L ...

  7. WinDbg 查看静态变量

    有如下Class.若想查看静态变量内容.因为静态变量和类绑定,仅需要查看类即可. namespace ConsoleApplication13 { class Program { public sta ...

  8. springboot在idea实现热部署

    1.在pom.xml引入热部署devtools依赖 <dependency> <groupId>org.springframework.boot</groupId> ...

  9. codeforces 696A A. Lorenzo Von Matterhorn(水题)

    题目链接: A. Lorenzo Von Matterhorn time limit per test 1 second memory limit per test 256 megabytes inp ...

  10. 非旋treap (BZOJ1895)

    记个板子,还是挺好用的. #include <bits/stdc++.h> using namespace std; ]; int rt,n,m,l,r,x,A,B,C,t; struct ...