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…
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.
1 6 1 2 4 5 6 3 3 0 2 5 1 3 7 0 2 5
240 420
#include<stdio.h>
#include<string.h>
#define mod 1000000007
using namespace std;
typedef long long ll;
const int N = 500005;
struct node{
int l,r;
ll sum;
}tree[N*4];
ll arr[N];
void build(int root,int l,int r){
tree[root].l=l;
tree[root].r=r;
if(l==r){
tree[root].sum=arr[l];
return;
}
int mid=(l+r)/2;
build(root*2,l,mid);
build(root*2+1,mid+1,r);
tree[root].sum=(tree[root*2].sum*tree[root*2+1].sum)%mod;
}
void update(int root,int pos,ll data){
if(tree[root].l==pos&&tree[root].r==pos){
tree[root].sum=data;
return;
}
int mid=(tree[root].l+tree[root].r)/2;
if(pos<=mid) update(root*2,pos,data);
else update(root*2+1,pos,data);
tree[root].sum=(tree[root*2].sum*tree[root*2+1].sum)%mod;
}
ll query(int root,int l,int r){
if(tree[root].l==l&&tree[root].r==r)
return tree[root].sum;
int mid=(tree[root].l+tree[root].r)/2;
if(r<=mid) return query(root*2,l,r);
else if(l>mid) return query(root*2+1,l,r);
else{
ll a=query(root*2,l,mid);
ll b=query(root*2+1,mid+1,r);
return a*b%mod;
}
}
int main(){
int T;
scanf("%d",&T);
while(T--){
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%lld",&arr[i]);
build(1,1,n);
int m;
scanf("%d",&m);
while(m--){
int op,a,b;
scanf("%d%d%d",&op,&a,&b);
if(op) update(1,a,b);
else printf("%lld\n",query(1,a,b)%mod);
}
}
return 0;
}