package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type rangeAddSegmentTree struct {
	size   int
	offset int
	data   []int
}

func newRangeAddSegmentTree(n int) rangeAddSegmentTree {
	var result rangeAddSegmentTree
	result.size = n
	t := 1
	for t < n {
		t *= 2
	}
	result.offset = t - 1
	result.data = make([]int, 2*t-1)
	return result
}

func (st rangeAddSegmentTree) rangeAdd(start, stop, value int) {
	l := start + st.offset
	r := stop + st.offset
	for l < r {
		if l&1 == 0 {
			st.data[l] += value
		}
		if r&1 == 0 {
			st.data[r-1] += value
		}
		l /= 2
		r = (r - 1) / 2
	}
}

func (st rangeAddSegmentTree) get(index int) int {
	i := index + st.offset
	result := st.data[i]
	for i > 0 {
		i = (i - 1) / 2
		result += st.data[i]
	}
	return result
}

func (st rangeAddSegmentTree) set(index, value int) {
	st.rangeAdd(index, index+1, value-st.get(index))
}

func (st rangeAddSegmentTree) bisectLeft(value int) int {
	return sort.Search(st.size, func(i int) bool { return st.get(i) >= value })
}

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 := newRangeAddSegmentTree(N + 1)
	for i := 0; i < N+1; i++ {
		st.rangeAdd(i, i+1, i)
	}

	for i := 0; i < Q; i++ {
		T := readInt()
		l := readInt() - 1
		r := readInt() - 1

		x := st.bisectLeft(l)
		y := st.bisectLeft(r+1) - 1
		if T == 1 {
			j := st.bisectLeft(r + 1)
			for k := j; k < y+1; k++ {
				st.set(k, st.get(x))
			}
			st.rangeAdd(y+1, N+1, l-r)
		} else if T == 2 {
			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...)
}