Pro.ID22157 TitleSequence Title链接http://10.20.2.8/oj/exercise/problem?problem_id=22157 AC0 Submit0 Ratio- 时间&空间限制描述Let S be a sequence of n integers, where S[k] with 1 ≤ k ≤ n denotes the k-th number of S. There is two kinds operation: 1) move(a, b, c): Move the subsequence S[a]..S[b] to the back of S[c]. If c equals 0, move the subsequence to the head of S. 2) sum(a, b): Calculate the sum of S[a]..S[b], output it. Your task is to write a program, which
输入The first line of the input is a single number T, the number of the test cases of the input. Then T blocks each represent a single test case. The first line of each block contains two integers N and M, representing N numbers and M instruction. The second line contains N 32-bit integers, giving sequence S. Then M lines that is in the following format: Move a b c or Sum a b 1 ≤ a ≤ b ≤ N, 0 ≤ c ≤ N, c < a or c > b. 输出Description Let S be a sequence of n integers, where S[k] with 1 ≤ k ≤ n denotes the k-th number of S. There is two kinds operation: 1) move(a, b, c): Move the subsequence S[a]..S[b] to the back of S[c]. If c equals 0, move the subsequence to the head of S. 2) sum(a, b): Calculate the sum of S[a]..S[b], output it. Your task is to write a program, which
Input The first line of the input is a single number T, the number of the test cases of the input. Then T blocks each represent a single test case. The first line of each block contains two integers N and M, representing N numbers and M instruction. The second line contains N 32-bit integers, giving sequence S. Then M lines that is in the following format: Move a b c or Sum a b 1 ≤ a ≤ b ≤ N, 0 ≤ c ≤ N, c < a or c > b. Output For each Sum operation, output one integer to represent the result, ( i.e. the sum of S[a], S[a+1], ..., S[b] ) Sample Input 2 Sample Output 10 Source 样例输入2 样例输出10 作者 |