AddK

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

You are given an array AA of NN integers A_1,,A_NA\_1, \dots , A\_N and an integer KK. You must process QQ queries of the following two types:

  • 1,i_1,i_2, ,i_K1 \\, i\_1 \\, i\_2 \\, \dots \\, i\_K: you must circularly permute A_i_1,,A_i_KA\_{i\_1} , \dots , A\_{i\_K} to the left. Thus the new values of elements A_i_1,A_i_2,,A_i_K1,A_i_KA\_{i\_1} , A\_{i\_2} , \dots , A\_{i\_{K-1}} , A\_{i\_K} will be A_i_2,A_i_3, ,A_i_K,A_i_1A\_{i\_2} , A\_{i\_3} , \dots , A\_{i\_K} , A\_{i\_1}. Note that i_1,,i_ki\_1, \dots , i\_k are distinct and not necessarily in increasing order.
  • 2,l,r ,m2 \\, l \\, r \\, m: you must sum the elements of all continuous subsequences with length mm from the sequence A_l,A_l+1,,A_r1,A_rA\_l , A\_{l+1}, \dots , A\_{r-1}, A\_r. Note that an element that appears in multiple subsequences must be added multiple times.

입력

The first line of the input contains two integers, NN and KK. The second line contains NN integers: the elements of array AA. The third line contains an integer QQ, the number of queries, and next QQ lines consists of queries, which can be one of two types described above.

출력

The output consists of the answer to the queries of type 22, every answer on a new line.

제한

  • 0A_i1060 ≤ A\_i ≤ 10^6
  • 1lrN1 ≤ l ≤ r ≤ N
  • 1mrl+11 ≤ m ≤ r - l + 1

힌트

The first query is of type 22 and we must calculate the sum of elements of all continuous subsequences with length m=4m = 4 from sequence (2,5,1,9,3,4)(2, 5, 1, 9, 3, 4). These subsequences are (2,5,1,9)(2, 5, 1, 9), (5,1,9,3)(5, 1, 9, 3), (1,9,3,4)(1, 9, 3, 4), and the sum of their elements is 52.

The second query is of type 11 and requires the circular permutation of elements from array AA, situated at indexes 22, 55, 88. So, the array AA will become (7,9,5,1,6,3,4,2)(7, 9, 5, 1, 6, 3, 4, 2).

The third query is of type 22 and we must calculate the sum of elements of all continuous subsequences with length m=3m = 3 from sequence (9,5,1,6,3,4)(9, 5, 1, 6, 3, 4). These subsequences are (9,5,1),(5,1,6),(1,6,3),(6,3,4)(9, 5, 1), (5, 1, 6), (1, 6, 3), (6, 3, 4), and the sum of their elements is 5050.