标签:
1 6 1 2 4 5 6 3 3 0 2 5 1 3 7 0 2 5
240 420
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long LL; 4 const int maxn = 50010; 5 const LL mod = 1000000007; 6 LL tree[maxn<<2]; 7 void build(int L,int R,int v){ 8 if(L == R){ 9 scanf("%I64d",tree+v); 10 return; 11 } 12 int mid = (L + R)>>1; 13 build(L,mid,v<<1); 14 build(mid+1,R,v<<1|1); 15 tree[v] = tree[v<<1]*tree[v<<1|1]%mod; 16 } 17 void update(int L,int R,int lt,int rt,int val,int v){ 18 if(lt <= L && rt >= R) { 19 tree[v] = val; 20 return; 21 } 22 int mid = (L + R)>>1; 23 if(lt <= mid) update(L,mid,lt,rt,val,v<<1); 24 if(rt > mid) update(mid+1,R,lt,rt,val,v<<1|1); 25 tree[v] = tree[v<<1]*tree[v<<1|1]%mod; 26 } 27 LL query(int L,int R,int lt,int rt,int v){ 28 if(lt <= L && rt >= R) return tree[v]; 29 int mid = (L + R)>>1; 30 LL ans = 1; 31 if(lt <= mid) ans *= query(L,mid,lt,rt,v<<1); 32 if(rt > mid) ans *= query(mid+1,R,lt,rt,v<<1|1); 33 return ans%mod; 34 } 35 int main(){ 36 int T,n,m,op,a,b; 37 scanf("%d",&T); 38 while(T--){ 39 scanf("%d",&n); 40 build(1,n,1); 41 scanf("%d",&m); 42 while(m--){ 43 scanf("%d %d %d",&op,&a,&b); 44 if(op) update(1,n,a,a,b,1); 45 else printf("%I64d\n",query(1,n,a,b,1)); 46 } 47 } 48 return 0; 49 }
标签:
原文地址:http://www.cnblogs.com/crackpotisback/p/4437583.html