Codeforces Round 141 (Div. 2)
D
Zigzag
Codeforces
2100
原题
← CE →
翻译中…

The court wizard Zigzag wants to become a famous mathematician. For that, he needs his own theorem, like the Cauchy theorem, or his sum, like the Minkowski sum. But most of all he wants to have his sequence, like the Fibonacci sequence, and his function, like the Euler's totient function.

翻译中…

The Zigag's sequence with the zigzag factor z is an infinite sequence $*S*_{*i*}^{*z*}$ $(*i* ≥ 1; *z* ≥ 2)$, that is determined as follows:

翻译中…
  • $*S*_{*i*}^{*z*} = 2$, when image;
  • image, when image;
  • image, when image.
翻译中…

Operation image means taking the remainder from dividing number $*x*$ by number $*y*$. For example, the beginning of sequence $*S*_{*i*}^{3}$ (zigzag factor 3) looks as follows: 1, 2, 3, 2, 1, 2, 3, 2, 1.

翻译中…

Let's assume that we are given an array $*a*$, consisting of $*n*$ integers. Let's define element number $*i*$ $(1 ≤ *i* ≤ *n*)$ of the array as $*a*_{*i*}$. The Zigzag function is function image, where $*l*, *r*, *z*$ satisfy the inequalities $1 ≤ *l* ≤ *r* ≤ *n*$, $*z* ≥ 2$.

翻译中…

To become better acquainted with the Zigzag sequence and the Zigzag function, the wizard offers you to implement the following operations on the given array $*a*$.

翻译中…
  1. The assignment operation. The operation parameters are $(*p*, *v*)$. The operation denotes assigning value $*v*$ to the $*p*$-th array element. After the operation is applied, the value of the array element $*a*_{*p*}$ equals $*v*$.
  2. The Zigzag operation. The operation parameters are $(*l*, *r*, *z*)$. The operation denotes calculating the Zigzag function $*Z*(*l*, *r*, *z*)$.
翻译中…

Explore the magical powers of zigzags, implement the described operations.

翻译中…

Input

翻译中…

The first line contains integer $*n*$ $(1 ≤ *n* ≤ 10^{5})$ — The number of elements in array $*a*$. The second line contains $*n*$ space-separated integers: $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ $(1 ≤ *a*_{*i*} ≤ 10^{9})$ — the elements of the array.

翻译中…

The third line contains integer $*m*$ $(1 ≤ *m* ≤ 10^{5})$ — the number of operations. Next $*m*$ lines contain the operations' descriptions. An operation's description starts with integer $*t*_{*i*}$ $(1 ≤ *t*_{*i*} ≤ 2)$ — the operation type.

翻译中…
  • If $*t*_{*i*} = 1$ (assignment operation), then on the line follow two space-separated integers: $*p*_{*i*}, *v*_{*i*}$ $(1 ≤ *p*_{*i*} ≤ *n*; 1 ≤ *v*_{*i*} ≤ 10^{9})$ — the parameters of the assigning operation.
  • If $*t*_{*i*} = 2$ (Zigzag operation), then on the line follow three space-separated integers: $*l*_{*i*}, *r*_{*i*}, *z*_{*i*}$ $(1 ≤ *l*_{*i*} ≤ *r*_{*i*} ≤ *n*; 2 ≤ *z*_{*i*} ≤ 6)$ — the parameters of the Zigzag operation.
翻译中…

You should execute the operations in the order, in which they are given in the input.

翻译中…

Output

翻译中…

For each Zigzag operation print the calculated value of the Zigzag function on a single line. Print the values for Zigzag functions in the order, in which they are given in the input.

翻译中…

Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specifier.

翻译中…

Note

翻译中…

Explanation of the sample test:

翻译中…
  • Result of the first operation is $*Z*(2, 3, 2) = 3·1 + 1·2 = 5$.
  • Result of the second operation is $*Z*(1, 5, 3) = 2·1 + 3·2 + 1·3 + 5·2 + 5·1 = 26$.
  • After the third operation array $*a*$ is equal to $2, 3, 5, 5, 5$.
  • Result of the forth operation is $*Z*(1, 5, 3) = 2·1 + 3·2 + 5·3 + 5·2 + 5·1 = 38$.
翻译中…

样例

Input #1
5
2 3 1 5 5
4
2 2 3 2
2 1 5 3
1 3 5
2 1 5 3
Output #1
5
26
38
InputCopy OutputCopy
题目信息
题号
228D
时间限制
3 s
内存限制
256 MB
标签
数据结构

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。