#FT0000020. Dãy số nhàm chán – Cộng cấp số cộng (Boring Sequence)
Bài tập thuộc lộ trình
Mục lục đề ⌄
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 indexed from . Process 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 terms, with first term and common difference . Add to , add to , ..., and add to . Equivalently, for every , increase by . Elements outside the interval remain unchanged. Both and may be negative.
Command 2 p asks for the current value of . Multiple progression updates may overlap and must accumulate. A query does not modify the array.
Input
- Line 1:
n mgives array length and command count. - Line 2:
a_1 a_2 ... a_ngives the initial values in index order. - Next lines: each line contains one of the following commands, in execution order:
1 l r K D: add an arithmetic progression starting at with difference to .2 p: query the value at position .
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):
- .
- .
- operation
1: . - operation
2: .
Subtask 2 (30 points):
- .
- .
- operation
1: . - operation
2: .
Subtask 3 (50 points):
- .
- .
- operation
1: . - operation
2: .
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 2 4 1 2: update interval , which has three elements. The arithmetic progression has first term and common difference , so the added values are , , and . Therefore changes from to , from to , and from to . The new array is[1, 3, 6, 9, 5]. -
2 3: query precisely . Its current value is , so print6. This is not a prefix-sum query.