We need to implement a program that supports range add updates and point queries. Since the initial values are 0 and updates are range add with constant x, and queries ask for a point value. This is classic: we can use a Fenwick tree (BIT) with range updates and point queries: BIT stores differences, then for add(s, t, x): update(s, x), update(t+1, -x). Then point query at i is prefix sum up to i. Complexity O((n+q) log n). n up to 100000, q up to 100000, fine.
Alternatively use a segment tree with lazy propagation but BIT is simpler.
We'll implement in Python. Input reading from sys.stdin.
But careful: constraints: x is between 0 and 1000, but values may become large? Up to q1000n? Actually worst-case: many updates on same range, sum up to 100000*1000 = 100 million, fits in 32-bit signed? Actually Python int is arbitrary.
We'll implement BIT as list of length n+2 (1-indexed). For update(pos, val): while pos <= n: bit[pos] += val; pos += pos & -pos. For query(pos): res = 0; while pos>0: res+=bit[pos]; pos -= pos & -pos; return res.
Then for each query:
If first integer == 0: s, t, x = next three ints. Update(s, x); update(t+1, -x) (if t+1 <= n).
If first integer == 1: i = next int. Print query(i).
Examples: Should work.
Edge cases: s, t are 1-indexed? Yes, given constraints: 1 ≤ s ≤ t ≤ n. So we use 1-indexed BIT.
We'll produce code.
But also note: Input includes n and q. Then q lines. We'll read all lines and parse.
We need to produce only for get operations.
Complexities fine.
Now produce final answer.
But the instruction: "Write a program which manipulates a sequence A..." and output for each get. We'll do that.
We'll provide a Python solution.
I'll include bit operations.
Let's craft code.
Potential improvements: Use sys.stdin.buffer.read and parse ints quickly due to large input. Since q up to 100k, plain input().split() is fine but we can optimize.
We'll implement using sys.stdin.buffer.read and map ints.
Implementation:
import sys
def main():
data = sys.stdin.buffer.read().split()
it = iter(data)
n = int(next(it))
q = int(next(it))
bit = [0]*(n+2)
def bit_add(i, val):
while i <= n:
bit[i] += val
i += i & -i
def bit_sum(i):
s = 0
while i > 0:
s += bit[i]
i -= i & -i
return s
out_lines = []
for _ in range(q):
typ = int(next(it))
if typ == 0:
s = int(next(it)); t = int(next(it)); x = int(next(it))
bit_add(s, x)
if t+1 <= n:
bit_add(t+1, -x)
else: # typ == 1
i = int(next(it))
out_lines.append(str(bit_sum(i)))
sys.stdout.write("\n".join(out_lines))
if name == "main":
main()
Yes.
Let's test with examples.
Example1:
n=3,q=5.
Updates: add 1 2 1 -> add(1,1); add(3,-1) (since t+1=3). Actually t=2 so t+1=3 <=3.
Then add 2 3 2 -> add(2,2); add(4,-1) but n=3 so we skip add(4).
Then add 3 3 3 -> add(3,3); add(4,-1) skip.
Query i=2: sum up to 2 = add(1,1) + add(2,2) = 3. correct? Actually also add(3,-1) affects if we sum up to 2, not included. So 3.
Query i=3: sum up to 3 = add(1,1) + add(2,2) + add(3,3) + effect of add(3,-1)? Wait careful: after first update: add(1,1), add(3,-1). After second: add(2,2), add(4,-1). After third: add(3,3). So BIT values: at index1:1, index2:2, index3: -1+3=2, index4: -1? But index4 not used. So prefix sum at 3 = 1+2+2=5. Yes.
Output:
3
5
Example2:
n=4,q=3.
First query get 2: initial all zero -> sum=0. output 0.
Then add 1 4 1: add(1,1); add(5,-1) but n=4 so skip add(5). So BIT: index1:1.
Then get 2: sum up to 2 =1 -> output 1. Output lines: 0 and 1.
Works.
Thus solution is correct.
But the problem may be from AIZU online judge? Possibly they want C++ but we are to provide Python? The user didn't specify language but typical answer is code. I'll provide Python.
If they want other language they would specify; but we assume Python.
Now final answer: Provide explanation and code.
I'll produce final message: Explanation: Use Binary Indexed Tree for range updates point queries. Then code.
Let's also note: The BIT stores the difference array.
Will output only code, perhaps with comments.
I'll respond.
```python
import sys
def main() -> None:
data = sys.stdin.buffer.read().split()
it = iter(data)
code
n = int(next(it))
q = int(next(it))
# BIT is 1-indexed; we allocate n+2 to safely access index n+1 if needed
bit = [0] * (n + 2)
def bit_add(idx: int, val: int) -> None:
"""add val at position idx (1-indexed)"""
while idx <= n:
bit[idx] += val
idx += idx & -idx
def bit_sum(idx: int) -> int:
"""prefix sum from 1 to idx"""
s = 0
while idx > 0:
s += bit[idx]
idx -= idx & -idx
return s
out_lines = []
for _ in range(q):
typ = int(next(it))
if typ == 0: # add(s, t, x)
s = int(next(it))
t = int(next(it))
x = int(next(it))
bit_add(s, x)
if t + 1 <= n:
bit_add(t + 1, -x)
else: # get(i)
i = int(next(it))
out_lines.append(str(bit_sum(i)))
sys.stdout.write("\n".join(out_lines))