Problem:
Range Add Query (RAQ)

Write a program which manipulates a sequence A = {a1, a2, . . . , an} with the following operations:

add(s, t, x): add x to as, as+1, ..., at.

get(i): output the value of ai.

Note that the initial values of ai (i = 1, 2, . . . , n) are 0.

Input

n q
query1
query2
:
queryq

In the first line, n (the number of elements in A) and q (the number of queries) are given. Then, ith query queryi is given in the following format:

0 s t x

or

1 t

The first digit represents the type of the query. '0' denotes add(s, t, x) and '1' denotes get(i).

Output

For each get operation, print the value.

Constraints

1 ≤ n ≤ 100000

1 ≤ q ≤ 100000

1 ≤ s ≤ t ≤ n

1 ≤ i ≤ n

0 ≤ x ≤ 1000

Sample Input 1

3 5
0 1 2 1
0 2 3 2
0 3 3 3
1 2
1 3

Sample Output 1

3
5

Sample Input 2

4 3
1 2
0 1 4 1
1 2

Sample Output 2

0
1

Solution in C++14 (judge verdict: Accepted)

#include <vector>
#include <functional>
using namespace std;

template <typename T, typename E>
class lazy_segtree {
private:
    using Op = function<T(T, T)>;
    using Compose = function<E(E, E)>;
    using Act = function<T(T, E)>;
    using Power = function<E(E, int)>;

    size_t N;
    vector<T> data;
    vector<E> lazy;
    const T idT;
    const E idE;
    const Op op;
    const Compose compose;
    const Act act;
    const Power power;

    void eval(size_t k, size_t len) {
        if(lazy[k] == idE) return;
        if(2 * k + 1 < 2 * N) {
            lazy[2 * k] = compose(lazy[2 * k], lazy[k]);
            lazy[2 * k + 1] = compose(lazy[2 * k + 1], lazy[k]);
        }
        data[k] = act(data[k], power(lazy[k], len));
        lazy[k] = idE;
    }

    void update(size_t a, size_t b, size_t k, size_t l, size_t r, E x) {
        eval(k, r - l);
        if(r <= a || b <= l) return;
        if(a <= l && r <= b) {
            lazy[k] = compose(lazy[k], x);
            eval(k, r - l);
            return;
        }
        update(a, b, 2 * k, l, (l + r) / 2, x);
        update(a, b, 2 * k + 1, (l + r) / 2, r, x);
        data[k] = op(data[2 * k], data[2 * k + 1]);
    }

    T get(size_t a, size_t b, size_t k, size_t l, size_t r) {
        eval(k, r - l);

        if(r <= a || b <= l) return idT;
        if(a <= l && r <= b) return data[k];
        
        T vl = get(a, b, 2 * k, l, (l + r) / 2);
        T vr = get(a, b, 2 * k + 1, (l + r) / 2, r);
        if(2 * k + 1 < 2 * N) data[k] = op(data[2 * k], data[2 * k + 1]);
        return op(vl, vr);
    }

public:
    lazy_segtree(size_t n, T idT, E idE,
    const Op op, const Compose compose,
    const Act act, const Power power = [](E a, int b){ return a; })
    : idT(idT), idE(idE), op(op), compose(compose), act(act), power(power) {
        for(N = 1; N < n; N <<= 1);
        data = vector<T>(2 * N, idT);
        lazy = vector<E>(2 * N, idE);
    }
    
    lazy_segtree(const vector<T> &init, T idT, E idE,
    const Op op, const Compose compose,
    const Act act, const Power power = [](E a, int b){ return a; })
    : idT(idT), idE(idE), op(op), compose(compose), act(act), power(power) {
        for(N = 1; N < init.size(); N <<= 1);
        data = vector<T>(2 * N, idT);
        lazy = vector<E>(2 * N, idE);
        for(int i = 0; i < init.size(); ++i) data[i + N] = init[i];
        for(int i = N - 1; i >= 0; --i) data[i] = op(data[2 * i], data[2 * i + 1]);
    }

    void update(size_t left, size_t right, E x) {
        update(left, right, 1, 0, N, x);
    }

    T get(size_t left, size_t right) {
        return get(left, right, 1, 0, N);
    }

    T operator[](int k) {
        return get(k, k + 1);
    }
};

#include <iostream>

int main() {
    int n, q;
    cin >> n >> q;
    lazy_segtree<long long, long long> st(n, 0, 0,
    plus<long long>(), plus<long long>(), plus<long long>(), multiplies<long long>());

    while(q--) {
        int c; cin >> c ;
        if(c == 0) {
            int s, t; long long x;
            cin >> s >> t >> x;
            st.update(s - 1, t, x);
        } else {
            int i; cin >> i;
            cout << st[i - 1] << endl;
        }
    }
}