import java.lang.*;
import java.io.*;
import java.util.*;
import java.math.*;
public class reverse_sk_treap
{
final int maxn = (int)2e5 + 10;
final int inf = (int)1e9;
class Tree
{
Tree l, r;
int si, x, y, rev;
long sum;
}
Tree Null = new Tree();
void Calc( Tree t )
{
t.si = 1 + t.l.si + t.r.si;
t.sum = t.x + t.l.sum + t.r.sum;
}
void Down( Tree t )
{
if (t.rev == 1)
{
t.l.rev ^= 1;
t.r.rev ^= 1;
Tree tmp = t.l; t.l = t.r; t.r = tmp;
t.rev = 0;
}
}
Tree NewT( int x, int y )
{
Tree T = new Tree();
T.x = x; T.sum = x; T.y = y; T.si = 1;
T.l = T.r = Null;
return T;
}
Tree L, R;
void Split( Tree t, int num )
{
if (t == Null)
{
L = Null;
R = Null;
return;
}
Down(t);
if (t.l.si >= num) {
Split(t.l, num); t.l = R; Calc(R = t);
} else {
Split(t.r, num - t.l.si - 1); t.r = L; Calc(L = t);
}
}
Tree Merge( Tree l, Tree r )
{
if (l == Null)
return r;
if (r == Null)
return l;
Tree res;
if (l.y < r.y) {
Down(res = l); l.r = Merge(l.r, r);
} else {
Down(res = r); r.l = Merge(l, r.l);
}
Calc(res);
return res;
}
long sum;
Tree Do( Tree t, int l, int r, int is )
{
Tree a, b, c, tmp;
Split(t, l); a = L; tmp = R;
Split(tmp, r - l); b = L; c = R;
sum = b.sum;
b.rev ^= is;
tmp = Merge(a, b);
return Merge(tmp, c);
}
Random random = new Random((int)1e9 + 7);
Tree Add( Tree t, int x )
{
int rand = random.nextInt();
return Merge(t, NewT(x, rand));
}
BufferedReader in;
StringTokenizer st = new StringTokenizer("");
int nextInt() throws Exception
{
while (!st.hasMoreTokens())
st = new StringTokenizer(in.readLine());
return Integer.valueOf(st.nextToken());
}
public void run()
{
try {
in = new BufferedReader(new FileReader(new File("reverse.in")));
PrintWriter out = new PrintWriter(new File("reverse.out"));
Tree t = Null;
int n = nextInt();
int k = nextInt();
for (int i = 0; i < n; i++)
{
int x = nextInt();
t = Add(t, x);
}
for (int i = 0; i < k; i++)
{
int type = nextInt();
int l = nextInt();
int r = nextInt();
t = Do(t, l - 1, r, type);
if (type == 0)
out.println(sum);
}
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
static public void main( String[] args )
{
new reverse_sk_treap().run();
}
}