#include <math.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#define MaxN 100010
#define MaxBuf 1<<22
#define L long long
#define RG register
#define inline __inline__ __attribute__((always_inline))
#define Blue() (S == T&&(T=(S=B)+fread(B,1,MaxBuf,stdin),S == T) ? 0 : *S++)
#define dmin(x,y) ((x) < (y)?(x):(y))
char B[MaxBuf],*S=B,*T=B;
inline void Rin(RG int &x) {
x=0;RG int c=Blue(),f=1;
for(; c < 48||c > 57; c=Blue())
if(c == 45)f=-1;
for(; c > 47&&c < 58; c=Blue())
x=(x<<1)+(x<<3)+c-48;
x*=f; }
L sl[MaxN],sr[MaxN],ans[MaxN];
int n,m,a[MaxN],block_size,log_pre[MaxN],pl[MaxN],pr[MaxN],_pb[MaxN];
struct Pr{
int fir,sec;
Pr() {}
Pr(RG int _,RG int __) : fir(_),sec(__) {}
bool operator < (const Pr &other) const {
return fir < other.fir; } }f[MaxN][20];
struct Request{
int l,r,id,belong;
bool operator < (const Request &other) const {
if(belong == other.belong)
return r < other.r;
return belong < other.belong; } }Q[MaxN];
inline void Rmq_Init() {
for(RG int i=1; i<18; i++)
log_pre[1<<i]=1;
for(RG int i=1; i<=n; i++)
log_pre[i]+=log_pre[i-1];
for(RG int i=1; i<=n; i++)
f[i][0]=Pr(a[i],i);
for(RG int k=1; k<18; k++)
for(RG int i=1; i<=n-(1<<k)+1; i++)
f[i][k]=dmin(f[i][k-1],f[i+(1<<k-1)][k-1]); }
inline int Rmq_Query(RG int l,RG int r) {
RG int tim=log_pre[r-l+1];
return dmin(f[l][tim],f[r-(1<<tim)+1][tim]).sec; }
inline void Mono_Stack() {
RG int top=0,i;
for(i=1; i<=n; i++) {
while(top && a[_pb[top]] > a[i])
pr[_pb[top]]=i,top--;
_pb[++top]=i; }
while(top)pr[_pb[top]]=n+1,top--;
for(i=n; i; i--) {
while(top && a[_pb[top]] > a[i])
pl[_pb[top]]=i,top--;
_pb[++top]=i; }
while(top)pl[_pb[top]]=0,top--;
for(i=1; i<=n; i++)
sl[i]=sl[pl[i]]+(L)a[i]*(i-pl[i]);
for(i=n; i; i--)
sr[i]=sr[pr[i]]+(L)a[i]*(pr[i]-i);
}
inline L extend(RG int l,RG int r,RG bool c) {
RG int x=Rmq_Query(l,r);
return c ? (L)a[x]*(x-l+1)+sl[r]-sl[x] :
(L)a[x]*(r-x+1)+sr[l]-sr[x];
}
inline void block_solve() {
RG L ans;
RG int l,r,i;
for(i=1; i<=m; i++) {
if(i == 1||Q[i].belong != Q[i-1].belong)
r=(Q[i].belong-1)*block_size,l=r+1,ans=0;
while(r < Q[i].r)
ans+=extend(l,++r,1);
while(l < Q[i].l)
ans-=extend(l++,r,0);
while(l > Q[i].l)
ans+=extend(--l,r,0);
:: ans[Q[i].id]=ans; } }
int main() {
Rin(n),Rin(m);
block_size=static_cast<int>(sqrt(n));
for(RG int i=1; i<=n; i++)
Rin(a[i]);
for(RG int i=1; i<=m; i++)
Rin(Q[i].l),Rin(Q[i].r),Q[i].id=i,Q[i].belong=(Q[i].l-1)/block_size+1;
std::sort(Q+1,Q+1+m);
Rmq_Init();
Mono_Stack();
block_solve();
for(RG int i=1; i<=m; i++)
printf("%lld\n",ans[i]);
return 0; }