def main(): import sys input=sys.stdin.readline n,q=map(int,input().split()) a=list(map(int,input().split())) #BIT dat=[0]*(n+10) def add(i,a): i+=1 while i<=n: dat[i]+=a i+=i&-i def binary_search(x): i=1 while i*2<=n: i*=2 res=0 while i: if res+i<=n and x>dat[res+i]: x-=dat[res+i] res+=i i//=2 return res for i in range(n): add(i,1) #end for i in range(1,n): a[i]+=a[i-1] for _ in range(q): t,l,r=map(int,input().split()) if t==1: d=r-l for _ in range(d): add(binary_search(l+1),-1) else: R=binary_search(r+1)-1 L=binary_search(l) print(a[R]-(a[L-1] if L!=0 else 0)) main()