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 N 500005
#define mod 1000000007
struct Tree{
int l,r;
__int64 sum,add;
}tree[N<<2];
void pushup(int root){
if(tree[root].l==tree[root].r)return ;
tree[root].sum=tree[root<<1].sum*tree[root<<1|1].sum %mod;
return ;
}
void pushdown(int root){
if(tree[root].l==tree[root].r)return ;
if(tree[root].add==-1)return ;
tree[root<<1].add=tree[root<<1|1].add=tree[root].add;
tree[root<<1].sum=(tree[root<<1].r-tree[root<<1].l+1)*tree[root].add;
tree[root<<1|1].sum=(tree[root<<1|1].r-tree[root<<1|1].l+1)*tree[root].add;
tree[root].add=-1;
return;
}
void update(int l,int r,int z,int root){
if(l==tree[root].l&&r==tree[root].r){
tree[root].sum=(tree[root].r-tree[root].l+1)*z;
tree[root].add=z;
return;
}
pushdown(root);
int mid=tree[root].l+tree[root].r>>1;
if(r<=mid)update(l,r,z,root<<1);
else if(l>mid)update(l,r,z,root<<1|1);
else {
update(l,mid,z,root<<1);
update(mid+1,r,z,root<<1|1);
}
pushup(root);
return;
}
void build(int l,int r,int root){
tree[root].l=l;
tree[root].r=r;
tree[root].sum=0;
tree[root].add=-1;
if(l==r){
tree[root].sum=1;
return;
}
int mid=(l+r)>>1;
build(l,mid,root<<1);
build(mid+1,r,root<<1|1);
pushup(root);
return ;
}
__int64 query(int l,int r,int root){
if(l==tree[root].l&&r==tree[root].r)
return tree[root].sum;
pushdown(root);
int mid=tree[root].l+tree[root].r>>1;
if(r<=mid)return query(l,r,root<<1);
else if(l>mid)return query(l,r,root<<1|1);
else return query(l,mid,root<<1)*query(mid+1,r,root<<1|1)%mod;
}
int main()
{
int T,i,j,k,n,q,k1,k2,a[50005],caozuo;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
build(1,n,1);
for(i=1;i<=n;i++)
{scanf("%d",&a[i]);
update(i,i,a[i],1);
}
scanf("%d",&q);
while(q--)
{
scanf("%d%d%d",&caozuo,&k1,&k2);
if(caozuo==0){
printf("%I64d\n",query(k1,k2,1));
}
if(caozuo==1)update(k1,k1,k2,1);
}
}
return 0;
}版权声明:本文为博主原创文章,未经博主允许不得转载。
原文:http://blog.csdn.net/aaaaacmer/article/details/46932389