segtree t,c; pair>> b[2d5]; ll n,q,bn,x,j,l,r,z[1d5]; { rd(n,q); t.walloc(n,1); c.walloc(n,1); rep(j,n)rd(x),b[bn++]={x,{j,{0,0}}}; rep(j,q)rd(x,l,r,x),b[bn++]={x,{j,{l,r}}}; sort(b,b+bn); for(;bn--;){ x=b[bn].first; j=b[bn].second.first; l=b[bn].second.second.first; r=b[bn].second.second.second; if(l){ z[j]=t.getSum(l-1,r)-c.getSum(l-1,r)*x; }else{ t.add(j,j+1,x); c.change(j,j+1,1); } } wtLn(z(q)); }