求解题思路求代码(线段树)

Inner Product
3000ms   /   65536KB   /   C, C++ or JAVA

Description

   The inner product of two integer sequences (or vectors) of the same length is defined as follows:

   <A, B> =A[1]*B[1] + A[2]*B[2] + ... + A[n]*B[n]

   You are going to calculate the inner product of two variable integer sequences. At the beginning, all elements of both sequences are zeros. Then several operations are applied to the sequences in turn. There are three types of operations:

   SET X i j k

   This operation sets X[i], X[i+1] ... X[j] to k. 1<= i, j <= n, 0 <= k <=1000000000.

   ADD X i j k

   This operation adds k to each of X[i], X[i+1] ... X[j]. 1<= i, j <= n, 0 <= k <=1000000000.

   SWAP i j

   This operations waps A[t] and B[t], t = i, i+1 ... J. 1<= i, j <= n.

   Please calculate the inner product of A and B after every operation.

Input Description
There are multiple test cases. The first line of a test case contains two positive integers N and M. N (N <= 100000) is the length of A and B. M (M <= 100000) is the number of operations. Then the following M lines each contains an operation.
Output Description
Print a line containing the answer of (<A, B> module 1000000007) after each operation. Print an empty line after each test case.
Sample Input
5 5
ADD A 1 2 3
SET B 2 3 4
SWAP 3 5
ADD B 3 4 5
SET A 4 5 1
Sample Output
0
12
12
32
37
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值