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

线段树区间单点更新,区间乘积查询。。

 1 #include<algorithm>
 2 #include<iostream>
 3 #include<cstdlib>
 4 #include<cstring>
 5 #include<cstdio>
 6 #define lc root<<1
 7 #define rc root<<1|1
 8 #define mid ((l+r)>>1)
 9 typedef unsigned long long ull;
10 const int Max_N = 50010;
11 const int Mod = 1000000007;
12 struct Node { int val; };
13 struct SegTree {
14     Node seg[Max_N << 2];
15     inline void push_up(int root) {
16         seg[root].val = (ull)seg[lc].val * seg[rc].val % Mod;
17     }
18     inline void built(int root, int l, int r) {
19         if (l == r) {
20             scanf("%d", &seg[root].val);
21             return;
22         }
23         built(lc, l, mid);
24         built(rc, mid + 1, r);
25         push_up(root);
26     }
27     inline void update(int root, int l, int r, int p, int v) {
28         if (p > r || p < l) return;
29         if (p <= l && p >= r) {
30             seg[root].val = v;
31             return;
32         }
33         update(lc, l, mid, p, v);
34         update(rc, mid + 1, r, p, v);
35         push_up(root);
36     }
37     inline int query(int root, int l, int r, int x, int y) {
38         if (x > r || y < l) return 1;
39         if (x <= l && y >= r) return seg[root].val;
40         int v1 = query(lc, l, mid, x, y);
41         int v2 = query(rc, mid + 1, r, x, y);
42         return (ull)v1 * v2 % Mod;
43     }
44 }seg;
45 int main() {
46 #ifdef LOCAL
47     freopen("in.txt", "r", stdin);
48     freopen("out.txt", "w+", stdout);
49 #endif
50     int t, n, q, a, b, c;
51     scanf("%d", &t);
52     while (t--) {
53         scanf("%d", &n);
54         seg.built(1, 1, n);
55         scanf("%d", &q);
56         while (q--) {
57             scanf("%d %d %d", &a, &b, &c);
58             if (!a) printf("%d\n", seg.query(1, 1, n, b, c));
59             else seg.update(1, 1, n, b, c);
60         }
61     }
62     return 0;
63 }
View Code

 

转载于:https://www.cnblogs.com/GadyPu/p/4539014.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值