hdu 5475 An easy problem(暴力 || 线段树区间单点更新)
http://acm.hdu.edu.cn/showproblem.php?pid=5475
An easy problem
Time Limit: 8000/5000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 755 Accepted Submission(s):
431
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.
are two integers Q and M. Q is the number of operations and M is described
above. (1≤Q≤10^5,1≤M≤10^9)
operation.
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.
Then Q lines follow,
each line please output an answer showed by the calculator.
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
#define Lson root<<1, L, tree[root].Mid()
#define Rson root<<1|1, tree[root].Mid() + 1, R const int N = ;
typedef long long ll; struct Tree
{
ll L, R;
ll sum;
int Mid()
{
return (L + R) / ;
}
} tree[N * ]; ll a[N], m; void Push(int root)
{
tree[root].sum = (tree[root<<].sum * tree[root<<|].sum) % m;
}//维护区间乘积 void Build(int root, ll L, ll R)
{
tree[root].L = L, tree[root].R = R;
if(L == R)
{
tree[root].sum = ;
return ;
} Build(Lson);
Build(Rson); Push(root);
}//建树 void Update(int root, ll op, ll e)
{
if(tree[root].L == op && tree[root].R == op)
{
tree[root].sum = e % m;
return ;
}
if(op <= tree[root].Mid())
Update(root<<, op, e);
else
Update(root<<|, op, e);
Push(root);
}//区间单点更新 int main()
{
int t, q, op, x = ;
scanf("%d", &t);
while(t--)
{
x++;
scanf("%d%lld", &q, &m);
printf("Case #%d:\n", x);
Build(, , q);
for(int i = ; i <= q ; i++)
{
scanf("%d%lld", &op, &a[i]);
if(op == )
Update(, i, a[i]);
else
Update(, a[i], );
printf("%lld\n", tree[].sum);
}
}
return ;
}
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<algorithm>
#define Lson root<<1, L, tree[root].Mid()
#define Rson root<<1|1, tree[root].Mid() + 1, R const int N = ;
typedef long long ll; ll a[N], m; int main()
{
int t, op, q, x = ;
scanf("%d", &t);
while(t--)
{
x++;
ll ans = ;
scanf("%d%lld", &q, &m);
printf("Case #%d:\n", x);
for(int i = ; i <= q ; i++)
{
scanf("%d%lld", &op, &a[i]);
if(op == )
ans = ans * a[i] % m;
else
{
a[a[i]] = ;
a[i] = ;
ans = ;
for(int j = ; j < i ; j++)
ans = ans * a[j] % m;
}
printf("%lld\n", ans);
}
}
return ;
}
hdu 5475 An easy problem(暴力 || 线段树区间单点更新)的更多相关文章
- HDU 1394 Minimum Inversion Number(线段树的单点更新)
点我看题目 题意 :给你一个数列,a1,a2,a3,a4.......an,然后可以求出逆序数,再把a1放到an后,可以得到一个新的逆序数,再把a2放到a1后边,,,,,,,依次下去,输出最小的那个逆 ...
- hdu 1394 Minimum Inversion Number(线段树之 单点更新求逆序数)
Minimum Inversion Number T ...
- HDU 1754 I Hate It(线段树之单点更新 区间最值查询)
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- hdu 1754 I Hate It(线段树之 单点更新+区间最值)
I Hate It Time Limit: 90 ...
- hdu1754线段树的单点更新区间查询
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total ...
- HDUOJ---1754 I Hate It (线段树之单点更新查区间最大值)
I Hate It Time Limit: 9000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
- HDU 1698 Just a Hook (线段树区间更新)
题目链接 题意 : 一个有n段长的金属棍,开始都涂上铜,分段涂成别的,金的值是3,银的值是2,铜的值是1,然后问你最后这n段总共的值是多少. 思路 : 线段树的区间更新.可以理解为线段树成段更新的模板 ...
- hdu 3911 Black And White (线段树 区间合并)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3911 题意: 给你一段01序列,有两个操作: 1.区间异或,2.询问区间最长的连续的1得长度 思路: ...
- HDU 3308 LCIS (线段树·单点更新·区间合并)
题意 给你一个数组 有更新值和查询两种操作 对于每次查询 输出相应区间的最长连续递增子序列的长度 基础的线段树区间合并 线段树维护三个值 相应区间的LCIS长度(lcis) 相应区间以左 ...
随机推荐
- hdu4618 Palindrome Sub-Array dp+记忆化搜索 或者直接暴力
题意就是找一个 左右上下对称的正方形矩阵. 连接:http://acm.hdu.edu.cn/showproblem.php?pid=4618 没想到记忆+dp和暴力就能水过... //记忆话搜索+d ...
- 淘宝主搜索离线集群完成Hadoop 2
淘宝搜索离线dump集群(hadoop&hbase)2013进行了几次重大升级,本文中将这些升级的详细过程.升级中所遇到的问题以及这些问题的解决方案分享给大家.至此,淘宝主搜索离线集群完全进入 ...
- 深入理解OpenERP的工作流(Workflow)
一.工作流定义: <?xml version="1.0"?> <terp><data> <record model="w ...
- hibernate不关闭session后果
(转自:百度知道) 看是怎么获得session的. 方法1: 通过配置监听器后,在Dao中用getCurrentSession获取(内部原理....),此时无需管理session的关闭与否: 方法2: ...
- (转) Python Generators(生成器)——yield关键字
http://blog.csdn.net/scelong/article/details/6969276 生成器是这样一个函数,它记住上一次返回时在函数体中的位置.对生成器函数的第二次(或第 n 次) ...
- (六) 6.3 Neurons Networks Gradient Checking
BP算法很难调试,一般情况下会隐隐存在一些小问题,比如(off-by-one error),即只有部分层的权重得到训练,或者忘记计算bais unit,这虽然会得到一个正确的结果,但效果差于准确BP得 ...
- 内存泄露(OOM)现象及举例
一.HeapSize OOM(堆空间内存溢出) A.eg:List.add(" ")在一个死循环中不断的调用add却没有remove. B.并发导致. 解决方法有:1.代码提速.这 ...
- mysql数据库中查询汉字的拼音首字母
本人提供的方法有如下特点: 1.代码精简,使用简单,只要会基本的SQL语句就行2.不用建立mysql 函数等复杂的东西3.汉字库最全,可查询20902个汉字 方法如下: 1.建立拼音首字母资料表Sql ...
- linux下动态库编译的依赖问题
这里主要是想试验一下,对一个具有多层嵌套的动态库进行编译时,是否要把最底层的库也包含进来的问题,结论是:只要直接依赖的库名称,不需要最底层库名称. 一,目录结构ZZZ├── add│ ├── ad ...
- 康乐不风流之爱解题的pde灌水王张祖锦
康乐不风流之爱解题的pde灌水王张祖锦 师弟: 邓洪存 (现在烟台大学任教) 好吧, 我一直想写写康乐园里与我相熟的这几个人, 不如趁此机会开始. 第一批人物为张祖锦.苏延辉.张会春.黄显涛.刘兴兴. ...