#include <bits/stdc++.h>
using namespace std;
const int N = 1001000;
struct BIT {
  int n;
  long long Tree[N];
  BIT(int n = 0) : n(n) {}
  void Init(int n) {
    this->n = n;
    for (int i = 0; i <= n; i++) Tree[i] = 0;
  }
  void Update(int i, int x) {
    for (; i <= n; i += i & -i) Tree[i] += x;
  }
  long long Query(int i) {
    long long Res = 0;
    for (; i > 0; i -= i & -i) Res += Tree[i];
    return Res;
  }
  long long Query(int i, int j) {
    if (i > j) return 0;
    return Query(j) - Query(i - 1);
  }
};
BIT myTree1;
BIT myTree2;
long long S(long long x) { return x * (x + 1) / 2; }
int main() {
  int n, q;
  cin >> n >> q;
  vector<int> a(n + 1);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  vector<int> L(q);
  vector<int> R(q);
  for (int& x : L) scanf("%d", &x);
  for (int& x : R) scanf("%d", &x);
  vector<long long> Ans(q);
  for (int Repeat = 0; Repeat < 2; Repeat++) {
    vector<int> LG(n + 1, 0);
    stack<int> stk;
    for (int i = n; i > 0; i--) {
      while (!stk.empty() && a[i] > a[stk.top()]) LG[stk.top()] = i, stk.pop();
      stk.push(i);
    }
    while (!stk.empty()) LG[stk.top()] = 0, stk.pop();
    vector<vector<int>> HaveLG(n + 1);
    for (int i = 1; i <= n; i++) HaveLG[LG[i]].push_back(i);
    vector<vector<int>> HaveL(n + 1);
    for (int i = 0; i < q; i++) HaveL[L[i]].push_back(i);
    for (int i = 0; i < q; i++) Ans[i] += S(R[i]) - S(L[i] - 1);
    myTree1.Init(n);
    myTree2.Init(n);
    for (int i = 1; i <= n; i++) myTree1.Update(i, 1);
    for (int l = n; l > 0; l--) {
      for (int i : HaveLG[l]) {
        myTree1.Update(i, -1);
        myTree2.Update(i, l);
      }
      for (int i : HaveL[l]) {
        int r = R[i];
        Ans[i] -=
            myTree2.Query(l, r) + (long long)(l - 1) * myTree1.Query(l, r);
      }
    }
    reverse(a.begin() + 1, a.end());
    for (int i = 0; i < q; i++) {
      L[i] = n - L[i] + 1;
      R[i] = n - R[i] + 1;
      swap(L[i], R[i]);
    }
  }
  for (int i = 0; i < q; i++) Ans[i] -= (long long)R[i] - L[i] + 1;
  for (long long x : Ans) printf("%I64d ", x);
}
