hdu 3074 Multiply game
题目连接
http://acm.hdu.edu.cn/showproblem.php?pid=3074
Minimum Inversion Number
Description
Tired of playing computer games, alpc23 is planning to play a game on numbers. Because plus and subtraction is too easy for this gay, he wants to do some multiplication in a number sequence. After playing it a few times, he has found it is also too boring. So he plan to do a more challenge job: he wants to change several numbers in this sequence and also work out the multiplication of all the number in a subsequence of the whole sequence.
To be a friend of this gay, you have been invented by him to play this interesting game with him. Of course, you need to work out the answers faster than him to get a free lunch, He he…
Input
The first line is the number of case T (T<=10).
For each test case, the first line is the length of sequence n (n<=50000), the second line has n numbers, they are the initial n numbers of the sequence a1,a2, …,an,
Then the third line is the number of operation q (q<=50000), from the fourth line to the q+3 line are the description of the q operations. They are the one of the two forms:
0 k1 k2; you need to work out the multiplication of the subsequence from k1 to k2, inclusive. (1<=k1<=k2<=n)
1 k p; the kth number of the sequence has been change to p. (1<=k<=n)
You can assume that all the numbers before and after the replacement are no larger than 1 million.
Output
For each of the first operation, you need to output the answer of multiplication in each line, because the answer can be very large, so can only output the answer after mod 1000000007.
Sample Input
1
6
1 2 4 5 6 3
3
0 2 5
1 3 7
0 2 5
Sample Output
240
420
线段树区间单点更新,区间乘积查询。。
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#define lc root<<1
#define rc root<<1|1
#define mid ((l+r)>>1)
typedef unsigned long long ull;
const int Max_N = ;
const int Mod = ;
struct Node { int val; };
struct SegTree {
Node seg[Max_N << ];
inline void push_up(int root) {
seg[root].val = (ull)seg[lc].val * seg[rc].val % Mod;
}
inline void built(int root, int l, int r) {
if (l == r) {
scanf("%d", &seg[root].val);
return;
}
built(lc, l, mid);
built(rc, mid + , r);
push_up(root);
}
inline void update(int root, int l, int r, int p, int v) {
if (p > r || p < l) return;
if (p <= l && p >= r) {
seg[root].val = v;
return;
}
update(lc, l, mid, p, v);
update(rc, mid + , r, p, v);
push_up(root);
}
inline int query(int root, int l, int r, int x, int y) {
if (x > r || y < l) return ;
if (x <= l && y >= r) return seg[root].val;
int v1 = query(lc, l, mid, x, y);
int v2 = query(rc, mid + , r, x, y);
return (ull)v1 * v2 % Mod;
}
}seg;
int main() {
#ifdef LOCAL
freopen("in.txt", "r", stdin);
freopen("out.txt", "w+", stdout);
#endif
int t, n, q, a, b, c;
scanf("%d", &t);
while (t--) {
scanf("%d", &n);
seg.built(, , n);
scanf("%d", &q);
while (q--) {
scanf("%d %d %d", &a, &b, &c);
if (!a) printf("%d\n", seg.query(, , n, b, c));
else seg.update(, , n, b, c);
}
}
return ;
}
hdu 3074 Multiply game的更多相关文章
- HDU 3074.Multiply game-区间乘法-线段树(单点更新、区间查询),上推标记取模
Multiply game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- 线段树 求区间连乘——hdu 3074 Multiply game
Multiply game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDU 3074 Multiply game(线段树)
单点更新,更新时先除去 原来的数,因为有去摸,可以用乘上逆元代替. //================================================================ ...
- hdu 3074 Multiply game(模板级线段树)
离机房关门还有十分钟,这点时间能干些什么?故作沉思地仰望星空,重新捋一下一天的学习进度,或者,砍掉一棵模板级线段树. 纯模板,就是把单点更新,区间求和改为单点更新,区间求积. 1A. #include ...
- HDU 3074 (线段树+模P乘法)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3074 题目大意:单点更新.维护序列乘法.mod 1000000007. 解题思路: 10000000 ...
- hdu 3074(线段树)
Multiply game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- hdu 3074 Zjnu Stadium (带权并查集)
Zjnu Stadium Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- hdu 3074 求区间乘积
线段树水题 #include<stdio.h> #include<string.h> #include<iostream> using namespace std; ...
- HDU 5475(2015 ICPC上海站网络赛)--- An easy problem(线段树点修改)
题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5475 Problem Description One day, a useless calculato ...
随机推荐
- Facebook等使用苹果源生分享
1.Facebook官方的SDK分享 2.ShareSDK,第三方集成的分享方式 3.网页分享方式分享 4.IOS6之后,苹果自己集成了对于F ...
- ASP.NET知识集
ASP.NET知识集 编辑删除转载2015-06-23 16:31:55 标签:it //删除指定行数据时,弹出询问对话框 ((LinkButton)(e.Row.Cell[7].Controls[0 ...
- 更改Pch配置
在Build Settings 里搜索prefix 在第一个AppleLLVM.7.0 有一个 PrefixHeader 属性 在属性里添加 $(SRCROOT)/加上pch文件名字 然后编 ...
- leetcode279. Perfect Squares
learn from DP class Solution { public: int numSquares(int n) { if(n<=0)return 0; int * dp = new i ...
- infusion度量金字塔数据解释
inFusion能够探测超过20中代码味道和代码缺陷,包括重复代码,破坏封装的类(如数据类或者万能类),高耦合的方法和类,以及一些设计不合理的类继承结构.当我们使用inFusion工具分析代码时,在分 ...
- sotower1.5-LS_工作流容易出错的地方
流程代码如下: 1>LeiSheng.WorkFlow.FlowInfo fInfo = new LeiSheng.WorkFlow.FlowInfo(); 2&g ...
- JavaScript中this详解
这里的主题是 this ,不扯远了.this 本身原本很简单,总是指向类的当前实例,this 不能赋值.这前提是说 this 不能脱离 类/对象 来说,也就是说 this 是面向对象语言里常见的一个关 ...
- java基础知识梳理
java基础知识梳理 1 基本数据类型
- ajax翻页效果模仿yii框架
ajax翻页效果,模仿yii框架. 复制代码代码如下: <!DOCTYPE html> <html> <head> <title>ajax分页_w ...
- QQ消息99+形成--第三方开源--BezierView
Android第三方开源的BezierView实现了上述QQ的99+条未读消息气泡显示.Android开源BezierView在github上的项目主页是:https://github.com/che ...