Segment tree
Practice
0 (0 votes)
Math
Basic math
Algorithms
Problem
76% Success 278 Attempts 20 Points 2s Time Limit 256MB Memory 1024 KB Max Code

You are given an array \(A\) of \(N\) integers \((A_0,A_1,A_2,....,A_{n-1})\). You have to perform \(Q\) queries of two types :

You are give integer \(T\) for each query \(1\) is for update and \(2\) is for query . 

  1. Update : given three integers \(i,x,s\). Add \(x\) to \(A[i]\) and decrease all the other elements of \(A\) by \(s\) .
  2. Query : given an integer \(y\) find the value of \(A[y]\).

Note : Here we followed 0-based indexing

Input Format

The first line contains one integer \(N\) — the number of elements in the array.

The second line contains \(N\) integers \(A_0,A_1,A_2,...,A_{n-1}\) .

The next line contains one integer \(Q\) — the number of queries to process.

In each query you are given integer \(T\) .

If \(T = 1\) you are given three integers \(i,x\) and \(s\)

If \(T = 2\) you are given one integer \(y\)  

Output Format

For each query of type \(2\), print one integer — \(A[y]\) ( 0-based indexing ).

Constraints :

\(1 \leq N,Q \leq 10^5 \\ 1 \leq A[i] \leq 10^5 \\ 1 \leq T \leq 2 \\ 0 \leq i < N \\ 1 \leq x,s\leq 10^5 \\ 0 \leq y < N \\ \)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
2 votes
Tags:
Maths
Points:20
144 votes
Tags:
Ad-HocOpenApprovedSimple-mathEasyMathamatics
Points:20
Tags:
Basic Math