#include<fstream>
#define DIM 200005
using namespace std;
int n, i, q, x, y, u;
int v[DIM], c[DIM];
long long sum[DIM];
ifstream fin("secvcost.in");
ofstream fout("secvcost.out");
int main(){
    fin>> n >> q;
    for(i = 1; i <= n; i++){
        fin>> v[i];
    }
    u = 0;
    for(i = 1; i <= n; i++){
        while(u > 0 && v[ c[u] ] < v[i]){
            sum[ c[u] ] = v[ c[u] ] * 1LL * (i - c[u - 1] - 1);
            u--;
        }
        c[++u] = i;
    }
    while(u > 0){
        sum[ c[u] ] = v[ c[u] ] * 1LL * (n - c[u - 1]);
        u--;
    }
    for(i = 2; i <= n; i++){
        sum[i] += sum[i - 1];
    }
    for(; q; q--){
        fin>> x >> y;
        fout<< sum[y] - sum[x - 1] <<"\n";
    }
}
