19暑假线段树B题

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…

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.
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
1
6
1 2 4 5 6 3
3
0 2 5
1 3 7
0 2 5
Sample Output
240
420
区间乘法,和区间加法一样直接上代码

 #include<stdio.h>
    #define maxn 50010
    #define mod 1000000007
    long long mul[maxn<<2];
    int T,n,q;
    void pushup(int k)
    {
    	mul[k]=(mul[k<<1]*mul[k<<1|1])%mod;
    }
    void build(int l,int r,int k)
    {
    	if(l==r)
    	{
    		scanf("%lld",&mul[k]);
    		return;
    	}
    	int mid=(l+r)/2;
    	build(l,mid,k<<1);
    	build(mid+1,r,k<<1|1);
    	pushup(k);
    }
    void set(int l,int r,int k,int loc,int c)
    {
    	if(l==r)
    	{
    		mul[k]=c;
    		return;
    	}
    	int mid=(l+r)/2;
    	if(mid>=loc)
    	set(l,mid,k<<1,loc,c);
    	else
    	set(mid+1,r,k<<1|1,loc,c);
    	pushup(k);
    }
    long long query(int l,int r,int k,int L,int R)
    {
    	if(L<=l&&r<=R)
    	return mul[k];
    	int mid=(l+r)/2;
    	long long ans=1;
    	if(L<=mid)
    	ans=(ans*query(l,mid,k<<1,L,R))%mod;
    	if(mid<R)
    	ans=(ans*query(mid+1,r,k<<1|1,L,R))%mod;
    	return ans;	
    } 
    int main()
    {
    	scanf("%d",&T);
    	while(T--)
    	{
    		scanf("%d",&n);
    		build(1,n,1);
    		scanf("%d",&q);
    		while(q--)
    		{
    			int op,k1,k2;
    			scanf("%d%d%d",&op,&k1,&k2);
    			if(op==0)
    			printf("%lld\n",query(1,n,1,k1,k2));
    			else
    			set(1,n,1,k1,k2%mod);
    		}
    	}
    }
### 关于线段树的第六道练习 对于线段树的应用,在多个平台和资料中有丰富的练习供学习者挑战。具体到第六道练习的选择,这取决于具体的课程设置或在线评测系统的安排[^1]。 通常情况下,线段树相关的练习会逐步增加难度,从基础操作如单点更新、区间查询开始,逐渐过渡到更复杂的懒惰传播(Lazy Propagation)、多维线段树等问上。考虑到这一点,假设在一个典型的训练序列中,“智乃酱的平方数列”可能作为一道中级偏上的目出现,该不仅涉及到了基本的线段树构建与维护,还加入了对等差数列以及多项式的处理[^2]。 为了更好地理解这类问并找到特定编号目,建议访问专门提供此类资源的网站,比如牛客网或其他知名编程竞赛平台。这些平台上往往会有详细的分类标签帮助定位目标目。例如,在牛客网上可以通过搜索关键词“线段树”,然后按照推荐顺序浏览直到找到所需的第六[^3]。 另外值得注意的是,不同平台之间的目编排可能存在差异,因此所谓的“第六”并不是绝对固定的,而是相对而言的一个位置概念。如果希望获得最准确的结果,可以直接查阅所使用的教材或者在线课程的具体章节来确定哪一被指定为第六[^4]。 ```cpp // 下面是一个简单的线段树节点定义示例,用于解决某些类型的区间查询问 struct Node { int l, r; long long sum; // 区间总和 long long sum2; // 区间每个数字的平方和 long long add; // 加法懒标记 long long mul; // 乘法懒标记 }; ```
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值