Range Updates

View as PDF

Submit solution

Points: 100
Time limit: 2.0s
PyPy 3 5.0s
Python 3 5.0s
Memory limit: 977M

Author:
Problem type

Range Updates?

Given an array of n integers, compute the following queries:

  1. Increase the values from [l,r] by u.
  2. What is the value at position k.

Input

The first line conatins the integer n.

The second line contains the integers within the array: x_1,\dots,x_n.

The third line contains the integer q.

The following q lines contains either "1 l r u" or "2 k", representing each type of query.

Output

For each query of type 2, output the value at position k.

Constraints

  • 1 \le n \le 10^5
  • 1 \le q \le 10^5
  • 1 \le x_i, u \le 10^9
  • 1 \le k \le n
  • 1 \le l \le r \le n

Hint: Try to change this from a range-update point-query problem, into a point-update range-query problem. (or don't)

Example 1

Input
5
8 8 6 7 9 
10
1 1 4 3
1 4 5 9
1 1 4 1
2 4
2 3
2 3
2 2
1 1 2 9
1 4 5 1
2 5
Output
20
10
10
12
19

Comments

There are no comments at the moment.