题目连接

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的更多相关文章

  1. HDU 3074.Multiply game-区间乘法-线段树(单点更新、区间查询),上推标记取模

    Multiply game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  2. 线段树 求区间连乘——hdu 3074 Multiply game

    Multiply game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  3. HDU 3074 Multiply game(线段树)

    单点更新,更新时先除去 原来的数,因为有去摸,可以用乘上逆元代替. //================================================================ ...

  4. hdu 3074 Multiply game(模板级线段树)

    离机房关门还有十分钟,这点时间能干些什么?故作沉思地仰望星空,重新捋一下一天的学习进度,或者,砍掉一棵模板级线段树. 纯模板,就是把单点更新,区间求和改为单点更新,区间求积. 1A. #include ...

  5. HDU 3074 (线段树+模P乘法)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3074 题目大意:单点更新.维护序列乘法.mod 1000000007. 解题思路: 10000000 ...

  6. hdu 3074(线段树)

    Multiply game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  7. hdu 3074 Zjnu Stadium (带权并查集)

    Zjnu Stadium Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  8. hdu 3074 求区间乘积

    线段树水题 #include<stdio.h> #include<string.h> #include<iostream> using namespace std; ...

  9. HDU 5475(2015 ICPC上海站网络赛)--- An easy problem(线段树点修改)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=5475 Problem Description One day, a useless calculato ...

随机推荐

  1. IOS9以上如何导入铃声并设置

    1.打开iTunes,点击左侧的“音乐” .2.在右侧的MP3等音乐列表中选中一个要制作铃声的名字 .3.在这个名字上点击鼠标右键选择“显示简介”,在弹出窗口中选择“选项”.4.在选项标签栏中设定开始 ...

  2. 仅显示INPUT下边框

    最近在倒腾前端的页面,在某次的需求中我想要这样的一个效果——仅显示INPUT输入框的下边框,和我想象的编写方式不一致,每个标签都有其对应的默认样式,不同的浏览器也有其不同的渲染方式,当然这些知识现在我 ...

  3. Activity的task相关 详解

    task是一个具有栈结构的容器,可以放置多个Activity实例.启动一个应用,系统就会为之创建一个task,来放置根Activity:默认情况下,一个Activity启动另一个Activity时,两 ...

  4. codevs 1049 棋盘染色

    题目描述 Description 有一个5×5的棋盘,上面有一些格子被染成了黑色,其他的格子都是白色,你的任务的对棋盘一些格子进行染色,使得所有的黑色格子能连成一块,并且你染色的格子数目要最少.读入一 ...

  5. iOS地址编码解析

    - (void)viewDidLoad { [super viewDidLoad]; // 创建地址解析器 self.geocoder = [[CLGeocoder alloc] init]; } - ...

  6. 注册码 myeclipse6.5-6.8

    package controllersli; import java.io.BufferedReader; import java.io.IOException; import java.io.Inp ...

  7. SQL Server T-SQL高级查询(转)

    高级查询在数据库中用得是最频繁的,也是应用最广泛的.   Ø 基本常用查询   --select select * from student; --all 查询所有 select all sex fr ...

  8. hdu1864

    use the cnt as the limit. #include <string.h> #include <stdio.h> ],sum; ]; double a,b,c; ...

  9. 在网页中使用H1标记的须注意的事项

    H1标签是网站排名非常重要的一个因素,因此我们一定要正确使用它. 本文为你介绍H1标签使用的七大注意事项: 1.每个页面都应该有H1标签,H1标签是每个网页不可缺少的要素. 2.使用H1标签的内容应该 ...

  10. azure注册码

    用户名:aaa 注册秘钥:2GQrt5XHYY7SBK/4b22Gm4Dh8alaR0/0k3gEN5h7FkVPIn8oG3uphlOeytIajx 注册用户名:www.yuanxingku.com ...