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

来源:互联网 发布:知周长求直径 编辑:程序博客网 时间:2024/05/17 19:15
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 5ADD A 1 2 3SET B 2 3 4SWAP 3 5ADD B 3 4 5SET A 4 5 1
Sample Output
012123237