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 ...
随机推荐
- Flex开发自定义控件
前期准备: 点击File菜单 -> New -> MXML Component,然后弹出一个对话框. 在对话框中输入组件名,选择此组件继承的类型,如:Canvas,DataGrid,Com ...
- SDUT 2141 【TEST】数据结构实验图论一:基于邻接矩阵的广度优先搜索遍历
数据结构实验图论一:基于邻接矩阵的广度优先搜索遍历 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Discuss Problem ...
- HTTP 错误 500(Internal Server Error)
今天在用ajax请求页面的时候出现了这么一个错误:HTTP 错误 500(Internal Server Error) 由于提示较少,过了好一阵子才找到答案:ajax请求中调用了一个不存在的函数⊙﹏⊙ ...
- LA3902 Network
给出一棵树,对于每一个叶子节点要使得在它的k距离内至少一个节点被打了标记,(叶节点不能打标记,非叶结点也不必满足这个条件),现在已经有一个节点s被打了标记,问至少还要打几个标记(这表达能力也是捉急.. ...
- .NET本质论(4)应用程序对象HttpApplication
当HttpContext对象创建之后,HttpRuntime将随后创建一个用于处理请求的对象,这个对象的类型为HttpApplication. 在ASP.NET内部,HttpRuntime管理一个定 ...
- JS产生四位随机数的方法
<script>var charactors="1234567890"; var value='',i; for(j=1;j<=4;j++){ i = parse ...
- 2_2数据类型与C#部分语法[wp8特色开发与编程技巧]
2_2数据类型 -5min 类型介绍 在上个视频中我们构建了我们第一个应用.这一次我们要来了解下c#的数据类型 众所周知,在我们已认知的世界里,我们把文字分为数字与字符.在程序的世界里面我们把数据分为 ...
- Windows Phone 8 通过一个app启动另一个app
Winphone8 通过app启动第三方app需要被启动的app支持,具体操作步骤如下: 假设要通过PhoneApp2启动PhoneApp1 PhoneApp1端做的操作如下: 1.注册Protoco ...
- 使用TypeScript如何提升JavaScript编程效果?
TypeScript是个什么鬼?和JavaScript有什么关系? TypeScript是由微软开发的一种可快速入门的开源的编程语言,是JavaScript的一个超集,且向这个语言添加了可选的静态类型 ...
- VMware下安装的Mac OS X如何修改显示分辨率
VMware下安装的Mac OS X如何修改显示分辨率 我在Win7下利用VMware安装了苹果的Mac OS,安装成功启动后,发现分辨率为1920*1080,而宿机的分辨率是1366*768,我 ...