PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#FT0000020. Dãy số nhàm chán – Cộng cấp số cộng (Boring Sequence)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Dãy số nhàm chán – Cộng cấp số cộng (Boring Sequence)

Boring Sequence

Source: Luogu

Version: Phuoc Hung OJ Extended

Problem Statement

You are given a sequence of integers a1,a2,…,ana_1,a_2,\ldots,a_n indexed from 11. Process mm commands that either add an arithmetic progression to a consecutive interval or request a single element.

Command 1 l r K D describes an arithmetic progression of exactly r−l+1r-l+1 terms, with first term KK and common difference DD. Add KK to ala_l, add K+DK+D to al+1a_{l+1}, ..., and add K+(r−l)DK+(r-l)D to ara_r. Equivalently, for every l≤j≤rl\le j\le r, increase aja_j by K+(j−l)DK+(j-l)D. Elements outside the interval remain unchanged. Both KK and DD may be negative.

Command 2 p asks for the current value of apa_p. Multiple progression updates may overlap and must accumulate. A query does not modify the array.

Input

  • Line 1: n m gives array length and command count.
  • Line 2: a_1 a_2 ... a_n gives the initial values in index order.
  • Next mm lines: each line contains one of the following commands, in execution order:
    • 1 l r K D: add an arithmetic progression starting at KK with difference DD to [l,r][l,r].
    • 2 p: query the value at position pp.

Output

For each 2 p command, print the requested integer computed from the current state on its own line, in query order. Update commands produce no output.

Subtasks

Subtask 1 (20 points):

  • 1≤n,m≤241\le n,m\le 24.
  • −200≤ai,K,D≤200-200\le a_i,K,D\le 200.
  • operation 1: 1≤l≤r≤n1\le l\le r\le n.
  • operation 2: 1≤p≤n1\le p\le n.

Subtask 2 (30 points):

  • 1≤n,m≤12001\le n,m\le 1200.
  • −200≤ai,K,D≤200-200\le a_i,K,D\le 200.
  • operation 1: 1≤l≤r≤n1\le l\le r\le n.
  • operation 2: 1≤p≤n1\le p\le n.

Subtask 3 (50 points):

  • 1≤n,m≤1000001\le n,m\le 100000.
  • −200≤ai,K,D≤200-200\le a_i,K,D\le 200.
  • operation 1: 1≤l≤r≤n1\le l\le r\le n.
  • operation 2: 1≤p≤n1\le p\le n.

Examples

Input

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

Output

6

Explanation

The initial array is [1, 2, 3, 4, 5], and there are two commands.

  1. 1 2 4 1 2: update interval [2,4][2,4], which has three elements. The arithmetic progression has first term K=1K=1 and common difference D=2D=2, so the added values are 11, 1+2=31+2=3, and 1+2⋅2=51+2\cdot2=5. Therefore a2a_2 changes from 22 to 33, a3a_3 from 33 to 66, and a4a_4 from 44 to 99. The new array is [1, 3, 6, 9, 5].

  2. 2 3: query precisely a3a_3. Its current value is 66, so print 6. This is not a prefix-sum query.