package main import ( "bufio" "fmt" "os" "strconv" ) type segmentTree struct { data []int offset int } func newSegmentTree(n int) segmentTree { var result segmentTree t := 1 for t < n { t *= 2 } result.offset = t - 1 result.data = make([]int, 2*t-1) return result } func (st segmentTree) updateAll(a []int) { for i, v := range a { st.data[st.offset+i] = v } for i := st.offset - 1; i > -1; i-- { st.data[i] = st.data[i*2+1] + st.data[i*2+2] } } func (st segmentTree) add(index, value int) { i := st.offset + index st.data[i] += value for i >= 1 { i = (i - 1) / 2 st.data[i] = st.data[i*2+1] + st.data[i*2+2] } } func (st segmentTree) update(index, value int) { i := st.offset + index st.data[i] = value for i >= 1 { i = (i - 1) / 2 st.data[i] = st.data[i*2+1] + st.data[i*2+2] } } func (st segmentTree) query(start, stop int) int { result := 0 l := start + st.offset r := stop + st.offset for l < r { if l&1 == 0 { result += st.data[l] } if r&1 == 0 { result += st.data[r-1] } l = l / 2 r = (r - 1) / 2 } return result } func main() { defer flush() N := readInt() Q := readInt() A := make([]int, N) for i := 0; i < N; i++ { A[i] = readInt() if i != 0 { A[i] += A[i-1] } } st := newSegmentTree(N) for i := 0; i < Q; i++ { T := readInt() l := readInt() - 1 r := readInt() - 1 a := 0 b := l for { c := st.query(a, b) if c == 0 { break } a = b b += c } x := b if T == 1 { st.add(x, r-l) } else if T == 2 { a := 0 b := r for { c := st.query(a, b+1) if c == 0 { break } a = b + 1 b += c } y := b if x != 0 { println(A[y] - A[x-1]) } else { println(A[y]) } } } } const ( ioBufferSize = 1 * 1024 * 1024 // 1 MB ) var stdinScanner = func() *bufio.Scanner { result := bufio.NewScanner(os.Stdin) result.Buffer(make([]byte, ioBufferSize), ioBufferSize) result.Split(bufio.ScanWords) return result }() func readString() string { stdinScanner.Scan() return stdinScanner.Text() } func readInt() int { result, err := strconv.Atoi(readString()) if err != nil { panic(err) } return result } var stdoutWriter = bufio.NewWriter(os.Stdout) func flush() { stdoutWriter.Flush() } func println(args ...interface{}) (int, error) { return fmt.Fprintln(stdoutWriter, args...) }