#FT0000011. Cây Fenwick 2 – Cộng đoạn và hỏi điểm (Fenwick Tree 2 - Range Add Point Query)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Cây Fenwick 2 – Cộng đoạn và hỏi điểm (Fenwick Tree 2 - Range Add Point Query)
Fenwick Tree 2 - Range Add Point Query
Source: Luogu
Version: Phuoc Hung OJ Extended
Problem Statement
You are given an array of integers indexed from . An update can change several consecutive elements at once, and an element may be affected by multiple earlier updates.
Operation 1 l r k adds integer to each element . Both endpoints are included, and may be negative. Where updated intervals overlap, their increments accumulate.
Operation 2 x requests the current value of the single element , not the prefix sum through . Apply operations in order and print one answer for every type-2 command.
Input
- Line 1:
n mgives array length and operation 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: add to all elements in .2 x: query the current value of .
Output
For each 2 x 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 (30 points):
- .
- .
- are integers.
- and in command
1 l r k. - in query
2 x. - for every element at every moment.
Subtask 2 (40 points):
- .
- .
- are integers.
- and in command
1 l r k. - in query
2 x. - for every element at every moment.
Subtask 3 (30 points):
- .
- .
- are integers.
- and in command
1 l r k. - in query
2 x. - for every element at every moment.
Examples
Input
5 5
1 5 4 2 3
1 2 4 2
2 3
1 1 5 -1
1 3 5 7
2 4
Output
6
10
Explanation
There are elements. The initial values are [1, 5, 4, 2, 3].
-
Command 1 —
1 2 4 2: Add to every element of ; updated array:[1, 7, 6, 4, 3]. -
Command 2 —
2 3: The element at position currently equals ; print6. This is not a prefix sum. -
Command 3 —
1 1 5 -1: Add to every element of ; updated array:[0, 6, 5, 3, 2]. -
Command 4 —
1 3 5 7: Add to every element of ; updated array:[0, 6, 12, 10, 9]. -
Command 5 —
2 4: The element at position currently equals ; print10. This is not a prefix sum.
Collect the answers to output-producing commands in their input order, printing one answer per line.