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 Go (judge verdict: Accepted)

package main

import (
	"bufio"
	"bytes"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
	"strings"
)

//  長い入力を読む
func ReadLongLines(times int) ([]string, error) {
	result := make([]string, times)
	reader := bufio.NewReader(os.Stdin)
	buffer := bytes.NewBuffer(make([]byte, 0))
	readBytes := int64(2)
	for i := 0; i < times; i++ {
		for {
			readBuf, isPrefix, err := reader.ReadLine()
			// fmt.Printf("Reader.Read: %d\n", len(readBuf))
			readBytes += int64(len(readBuf) + 1)
			if err != nil {
				if err == io.EOF {
					fmt.Println("EOF")
					break
				} else {
					return result, err
				}
			}
			_, err = buffer.Write(readBuf)
			if err != nil {
				return result, err
			}
			// end of line
			if !isPrefix {
				result[i] = buffer.String()
				buffer.Reset()
				// reader = bufio.NewReader(os.Stdin)
				break
			}
		}
	}
	// 先読みしてしまうようなので、戻しておく
	os.Stdin.Seek(-int64(reader.Buffered()), os.SEEK_CUR)
	return result, nil
}

// 出力 for 競プロ
type Console struct {
	writer *bufio.Writer
}

func NewConsole() Console {
	return Console{bufio.NewWriter(os.Stdout)}
}
func (this *Console) Printf(format string, a ...interface{}) {
	fmt.Fprintf(this.writer, format, a...)
}
func (this *Console) Println(s string) {
	fmt.Fprintln(this.writer, s)
}
func (this *Console) Close() {
	this.Flush()
}
func (this Console) Flush() {
	this.writer.Flush()
}

func PrintList(list []int) {
	con := NewConsole()
	defer con.Flush()
	for i := range list {
		if i == 0 {
			con.Printf("%d", list[i])
		} else {
			con.Printf(" %d", list[i])
		}
	}
	con.Println("")
}

func Max(lhs int, rhs int) int {
	if lhs < rhs {
		return rhs
	} else {
		return lhs
	}
}
func Min(lhs int, rhs int) int {
	if lhs < rhs {
		return lhs
	} else {
		return rhs
	}
}

// const DEF_VAL = 1<<31 - 1
const DEV_VAL = 0

type List struct {
	data      []int
	sumBucket []int
	numVal    int
}

func NewList(n int) List {
	numVal := int(math.Floor(math.Sqrt(float64(n))))
	bucketNum := int(math.Ceil(float64(n) / float64(numVal)))
	bucket := make([]int, bucketNum)
	data := make([]int, n)
	return List{data, bucket, numVal}
}

func (this *List) GetIndex(begin int, end int) []int {
	// 範囲をカバーする minListのインデックスを計算する
	result := make([]int, 0)
	for i := begin; i < end/this.numVal*this.numVal+this.numVal; i += this.numVal {
		x := i / this.numVal
		result = append(result, x)
	}
	return result
}

func (this *List) Add(begin int, end int, value int) {
	// outside bucket
	for i := begin; i < (begin/this.numVal+1)*this.numVal && i <= end; i++ {
		// fmt.Printf("under %d\n", (begin/this.numVal+1)*this.numVal)
		this.data[i] += value
	}
	for i := end / this.numVal * this.numVal; i <= end && begin < i; i++ {
		// fmt.Printf("over")
		this.data[i] += value
	}
	// bucket
	for i := begin/this.numVal + 1; i < end/this.numVal; i++ {
		// fmt.Printf("bucket")
		this.sumBucket[i] += value
	}
}

func (this *List) Find(index int) int {
	return this.data[index] + this.sumBucket[index/this.numVal]
}

func main() {
	con := NewConsole()
	defer con.Close()

	var n, q int
	fmt.Scanf("%d %d", &n, &q)
	lines, _ := ReadLongLines(q)

	list := NewList(n)
	// fmt.Println(list)
	for i := 0; i < q; i++ {
		args := strings.Split(lines[i], " ")
		command := args[0]
		switch command {
		case "0":
			s, _ := strconv.Atoi(args[1])
			t, _ := strconv.Atoi(args[2])
			x, _ := strconv.Atoi(args[3])
			list.Add(s-1, t-1, x)
			// fmt.Println(list)
		case "1":
			i, _ := strconv.Atoi(args[1])
			x := list.Find(i - 1)
			// con.Printf("Find(%d, %d) ", s, t)
			con.Printf("%d\n", x)
		}
	}
	// fmt.Println(list)
}