Hdu3074_multiply game (line segment tree/Single Point update)

Source: Internet
Author: User

Solution report

Question:

Omitted

Ideas:

Single point update, interval product.

#include <cstdio>#include <iostream>#include <cstring>#define LL long longusing namespace std;LL mul[501000];void update(int root,int l,int r,int p,int v){    int mid=(l+r)/2;    if(l==r)mul[root]=v;    else    {        if(p<=mid)update(root*2,l,mid,p,v);        else update(root*2+1,mid+1,r,p,v);        mul[root]=(mul[root*2]*mul[root*2+1])%1000000007;    }}LL q_mul(int root,int l,int r,int ql,int qr){    int mid=(l+r)/2;    LL ans=1;    if(ql<=l&&r<=qr)return mul[root];    if(ql<=mid)ans=(ans*q_mul(root*2,l,mid,ql,qr))%1000000007;    if(mid<qr)ans=(ans*q_mul(root*2+1,mid+1,r,ql,qr))%1000000007;    return ans;}int main(){    int t,i,j,n,q,a,ql,qr,k;    scanf("%d",&t);    while(t--)    {        memset(mul,0,sizeof(mul));        scanf("%d",&n);        for(i=1; i<=n; i++)        {            scanf("%d",&a);            update(1,1,n,i,a);        }        scanf("%d",&q);        for(i=1; i<=q; i++)        {            scanf("%d%d%d",&k,&ql,&qr);            if(k)update(1,1,n,ql,qr);            else printf("%lld\n",q_mul(1,1,n,ql,qr));        }    }}

Multiply game Time Limit: 2000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 1431 accepted submission (s): 494


Problem descriptiontired 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 numbers in a subsequence of the whole sequence.
To be a friend of this gay, you have been broadcast ted 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...

 
Inputthe 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, intrusive. (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.
 
Outputfor 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
 
Source2009 multi-university training contest 17-host by nudt

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.