luogu#P16389. [IATI 2024] Five

[IATI 2024] Five

Problem Description

Due to unforeseen circumstances this task is not fifth.

A recent survey by polling agency "Ko & co"\verb|"Ko & co"| found that no one likes the numbers from 11 to 44. So we will focus on the next number, 55, and hope it does not follow the unfortunate fate of its predecessors.

Consider the following sequence in the positive and negative indices:

  • x0=0x_0 = 0
  • x1=1x_1 = 1
  • x2=2x_2 = 2
  • x3=3x_3 = 3
  • x4=4x_4 = 4
  • $x_{k+5} = 5 \times x_{k+4} + 4 \times x_{k+3} + 3 \times x_{k+2} + 2 \times x_{k+1} + 1 \times x_{k}$ for each integer kk.

Note that equality uniquely defines both the positive and the negative indices (e.g. x5=40,x6=230,x_5 = 40, x_6 = 230, \dots and x1=22,x2=33,x_{-1} = -22, x_{-2} = 33, \dots)

You are given an array of nn numbers a1,a2,,ana_1, a_2, \dots, a_n. Write a program five\texttt{five} that supports 22 types of events:

  • QueryQuery with parameters l,rl, r. We want to find the value $x_{a_{l}} + x_{a_{l + 1}} + ... + x_{a_{r}} = \sum_{i = l}^{r} x_{a_{i}}$. Since it can get very large, print the answer modulo M=108+543M = 10 ^ 8 + 543.
  • UpdateUpdate with parameters l,r,valuel, r, value. Then the new value of aia_i becomes equal to ai+valuea_i+value for every lirl \leq i \leq r.

Input Format

The first line of the standard input contains the numbers nn and qq. The next line contains nn integers a1,a2,,ana_1,a_2,…,a_n. Each of the following qq lines contains 33 natural numbers type,l,rtype, l, r.

If type=1type = 1, then the line is a QueryQuery.

If type=2type = 2, then the line is an UpdateUpdate and contains a further integer valuevalue.

Output Format

For each QueryQuery, print on a new line the answer for that query.

1 5
1
1 1 1
2 1 1 -2
1 1 1
2 1 1 8
1 1 1
1
100000521
1330

Hint

Sample Explanation

At the start a1=1a_1 = 1 and xa1=1x_{a_{1}} = 1. After the first UpdateUpdate a1=1a_1= -1 and xa1=22x_{a_{1}} = -22. After the second UpdateUpdate a1=7a_1 = 7 and xa1=1330x_{a_{1}} = 1330.

Constraints

  • 1n1000001 \leq n \leq 100 000
  • 1q2000001 \leq q \leq 200 000
  • 1lrn1 \leq l \leq r \leq n
  • M<ai,value<M- M < a_i, value < M

Subtasks

Subtask Points Additional constraints
11 55 0ai1060 \leq a_i \leq 10^6 and only QueryQuery
22 1919 0ai,value0 \leq a_i, value and l=rl = r
33 0ai,value0 \leq a_i, value and q20000q \leq 20 000
44 q20000q \leq 20 000
55 q100000q \leq 100 000
66 None

The points for a subtask are given only if all tests for it and the required subtasks are passed successfully.