HDU
来源:互联网 发布:js去掉属性值 编辑:程序博客网 时间:2024/06/05 04:09
Multiply game
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2765 Accepted Submission(s): 977
Problem 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…
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.
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
161 2 4 5 6 330 2 51 3 70 2 5
Sample Output
240420
Source
2009 Multi-University Training Contest 17 - Host by NUDT
题意:求区间积。
就是把线段树求和改成线段树求积就行了,然后要初始化1,不能为0.
在求和的过程中忘记取模了,一直没发现。。
在求和的过程中忘记取模了,一直没发现。。
#include<iostream>#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#define LL long longconst LL maxn = 50005;LL T,q,n,sum[maxn<<2],a[maxn],ans,mod = 1000000007,ope,k1,k2;void build(LL l,LL r,LL x){ sum[x]=1; if(l==r) { sum[x] = a[l]; return ; } LL m = (l+r)>>1; build(l,m,x<<1); build(m+1,r,x<<1|1); sum[x] =sum[x<<1] * sum[x<<1|1] % mod;}void Change(LL pos,LL l,LL r,LL x,LL C){ if(l==r) { sum[x] = C; return ; } LL m = (l+r)>>1; if(pos<=m) Change(pos,l,m,x<<1,C); else Change(pos, m+1, r, x<<1|1, C); sum[x] = sum[x<<1] * sum[x<<1|1] % mod;}LL Mul(LL L,LL R,LL l,LL r,LL x){ LL ans = 1,m = (l+r)>>1; if(l>=L&&r<=R) return sum[x]; if(L<=m) ans*=Mul(L,R,l,m,x<<1),ans%=mod; if(R>m) ans*=Mul(L, R, m+1, r, x<<1|1),ans%=mod; return ans;}int main(){ scanf("%lld",&T); while(T--) { for(int i=0;i<maxn;i++) sum[i] = 1; scanf("%lld",&n); for(int i=1;i<=n;i++) scanf("%lld",&a[i]); build(1, n, 1); scanf("%lld",&q); while(q--) { scanf("%lld%lld%lld",&ope,&k1,&k2); if(ope) Change(k1, 1, n, 1, k2); else printf("%lld\n",Mul(k1,k2,1,n,1)); } } return 0;}
阅读全文
0 0
- hdu
- hdu
- HDU
- hdu ()
- hdu
- hdu
- HDU
- HDU
- hdu
- hdu
- HDU
- Hdu
- hdu
- hdu-
- hdu
- hdu
- hdu
- HDU
- C++中堆栈的区别
- dubbo + jenkins持续集成 shell 脚本样例
- 浅谈PWM控制电机
- 虚拟机和物理机之间互ping【局域网内ping不通,防火墙规则更改(win7为例)】
- 常见的用户密码加密及破解方法
- HDU
- Java自定义注解Annotation
- iOS In-App Purchase 内购之 问题总结
- 测试
- Kylin v2.0.0开始参数配置规则发生变化
- stdio.h: C++输入输出操作
- GDB layout 命令
- 先码后看 HashMap底层 转侵删
- mysql 1449 : The user specified as a definer ('admin'@'%') does not exist 解决方法