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 ...
随机推荐
- Stay Hungry
保持饥饿,从身体上来说,可以随时保持机动状态,所以,今天的早饭.午饭.晚饭,我都没有吃到饱.等到想要放松的时候,就饱餐一顿,未必不是一种幸福!精神上,保持饥饿,我还不清楚是一种什么样的状态,自然也描述 ...
- Spring 3.0以后版本的定时任务
自主开发的定时任务工具,spring task,可以将它比作一个轻量级的Quartz,而且使用起来很简单,除spring相关的包外不需要额外的包,而且支持注解和配置文件两种 <beans xml ...
- 創建HTTP 服務器
var http = require('http'); var fs = require('fs'); var server = http.createServer(function(req, res ...
- SSIS Error Code DTS_E_OLEDB_NOPROVIDER_64BIT_ERROR
将一批Job从一台agent服务器搬到另外一台agent, 没有做任何的修改,但是job执行的时候报错. Error: 2014-07-03 14:42:57.14 Code: 0xC0209303 ...
- My Sql 1067错误兼编码问题解决
My Sql 大部分都是用绿色版(解压版) 然后注册服务 简单方便. 但是.配置文件头痛的一逼. 首先配置mysql的环境变量. mySQL 环境变量(我的电脑-右击属性-高级-环境变量) MYSQL ...
- C#使用Cookie方法
//写入 protected void Button1_Click(object sender, EventArgs e) { HttpCookie cookie=new HttpCookie(&qu ...
- windows installer 出错问题解决
在卸载程序的额时候,如果出现windows installer出错,可以通过一个Windows Installer CleanUp Utility, 有了Windows Installer Clean ...
- JS 和 CSS 的位置对其他资源加载顺序的影响
JS 和 CSS 在页面中的位置,会影响其他资源(指 img 等非 js 和 css 资源)的加载顺序,究其原因,有三个值得注意的点: JS 有可能会修改 DOM. 典型的,可能会有 document ...
- (笔记)angular material 选项卡用法
- SAS 5/iR Adapter 驱动下载
http://www.dell.com/support/home/cn/zh/cnbsd1/Drivers/DriversDetails?driverId=FF6F6