CF228D.Zigzag

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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 SizS_{i}^{z} (i>=1; z>=2)(i>=1; z>=2) , that is determined as follows:

  • Siz=2S_{i}^{z}=2 , when ;
  • , when ;
  • , when .

Operation means taking the remainder from dividing number xx by number yy . For example, the beginning of sequence Si3S_{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 aa , consisting of nn integers. Let's define element number ii (1<=i<=n)(1<=i<=n) of the array as aia_{i} . The Zigzag function is function , where l,r,zl,r,z satisfy the inequalities 1<=l<=r<=n1<=l<=r<=n , z>=2z>=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 aa .

  1. The assignment operation. The operation parameters are (p,v)(p,v) . The operation denotes assigning value vv to the pp -th array element. After the operation is applied, the value of the array element apa_{p} equals vv .
  2. The Zigzag operation. The operation parameters are (l,r,z)(l,r,z) . The operation denotes calculating the Zigzag function Z(l,r,z)Z(l,r,z) .

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

输入格式

The first line contains integer nn (1<=n<=105)(1<=n<=10^{5}) — The number of elements in array aa . The second line contains nn space-separated integers: a1,a2,...,ana_{1},a_{2},...,a_{n} (1<=ai<=109)(1<=a_{i}<=10^{9}) — the elements of the array.

The third line contains integer mm (1<=m<=105)(1<=m<=10^{5}) — the number of operations. Next mm lines contain the operations' descriptions. An operation's description starts with integer tit_{i} (1<=ti<=2)(1<=t_{i}<=2) — the operation type.

  • If ti=1t_{i}=1 (assignment operation), then on the line follow two space-separated integers: pi,vip_{i},v_{i} (1<=pi<=n; 1<=vi<=109)(1<=p_{i}<=n; 1<=v_{i}<=10^{9}) — the parameters of the assigning operation.
  • If ti=2t_{i}=2 (Zigzag operation), then on the line follow three space-separated integers: li,ri,zil_{i},r_{i},z_{i} (1<=li<=ri<=n; 2<=zi<=6)(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.

输出格式

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.

输入输出样例

  • 输入#1

    5
    2 3 1 5 5
    4
    2 2 3 2
    2 1 5 3
    1 3 5
    2 1 5 3
    

    输出#1

    5
    26
    38
    

说明/提示

Explanation of the sample test:

  • Result of the first operation is Z(2,3,2)=31+12=5Z(2,3,2)=3·1+1·2=5 .
  • Result of the second operation is Z(1,5,3)=21+32+13+52+51=26Z(1,5,3)=2·1+3·2+1·3+5·2+5·1=26 .
  • After the third operation array aa is equal to 2,3,5,5,52,3,5,5,5 .
  • Result of the forth operation is Z(1,5,3)=21+32+53+52+51=38Z(1,5,3)=2·1+3·2+5·3+5·2+5·1=38 .
首页