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 ...
随机推荐
- 【LeetCode】18. 4Sum
题目: 思路:这题和15题很像,外层再加一个循环稍作修改即可 public class Solution { public List<List<Integer>> fourSu ...
- 用Ossim管理IT资产(视频)
用Ossim管理IT资产 在Ossim中集成了Ocs Server,OCS用于帮助网络或系统管理员来跟踪网络中计算机配置与软件安装情况的应用程序.收集到硬件和系统信息,OCS Inventory 也可 ...
- 开源项目:FFmpeg
ffmpeg命令行使用 将JPG格式图片转成YUV420P格式: ffmpeg -i Z:\demo\pic.jpg -s 720x480 Z:\demo\pic.yuv 解码H265成YUV420 ...
- jquery css快捷方法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- [转载]word尾注插入参考文献——前人经验+自己总结
1. 以尾注的方式插入第一个参考文献. 将光标定位于word文档中将要插入参考文献的位置,按“插入/引用/脚注和尾注”.出现一菜单,选择“尾注”,“文档结尾”,编号格式为“1,2,3”.按“插入”按钮 ...
- Windows phone 8 学习笔记(5) 图块与通知(转)
基于metro风格的Windows phone 8 应用提到了图块的概念,它就是指启动菜单中的快速启动图标.一般一个应用必须有一个默认图块,还可以有若干个次要图块.另外,通知与图块的关系比较密切,我们 ...
- 如何根据IP查找计算机名
示例:nbtstat -A 192.168.1.123 参考网址:http://jingyan.baidu.com/article/335530daa40d7f19cb41c312.html
- windows server 备份与还原
1:文件备份: ①Goodsync ②Acronis Backup & Recovery 2:域控&系统备份 ①CMD -- >NTbackup (不支持异机还原) ②Acron ...
- leetcode 38
38. Count and Say The count-and-say sequence is the sequence of integers beginning as follows:1, 11, ...
- JAVA设计模式--State(状态模式)
状态模式(State Pattern)是设计模式的一种,属于行为模式. 定义(源于Design Pattern):当一个对象的内在状态改变时允许改变其行为,这个对象看起来像是改变了其类. 状态模式主要 ...