#include <bits/stdc++.h>
using namespace std;
struct fenwickTree {
  vector<long long> bit;
  int n;
  fenwickTree() {
    n = (int)1e6 + 3;
    bit.assign(n, 0);
  }
  long long sum(int r) {
    long long ret = 0;
    for (; r >= 0; r = (r & (r + 1)) - 1) ret += bit[r];
    return ret;
  }
  void add(int idx, long long d) {
    for (; idx < n; idx = idx | (idx + 1)) bit[idx] += d;
  }
  long long sum(int l, int r) { return sum(r) - sum(l - 1); }
} ft, ft01, ftIdentity;
struct query {
  int l, r, index;
};
bool cmpL(const query &x, const query &y) { return x.l < y.l; }
bool cmpRP(const pair<int, int> &x, const pair<int, int> &y) {
  return x.second < y.second;
}
bool cmpR(const query &x, const query &y) { return x.r < y.r; }
const int N = 1e6 + 10;
int perm[N], lefts[N], rights[N];
long long answer[N];
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, q;
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) {
    cin >> perm[i];
  }
  stack<int> positions;
  for (int i = 1; i <= n; ++i) {
    while (!positions.empty() && perm[positions.top()] <= perm[i])
      positions.pop();
    if (positions.empty()) {
      lefts[i] = 0;
    } else {
      lefts[i] = positions.top();
    }
    positions.push(i);
  }
  while (!positions.empty()) positions.pop();
  fill(rights, rights + n + 10, n + 1);
  for (int i = n; i >= 1; --i) {
    while (!positions.empty() && perm[positions.top()] <= perm[i])
      positions.pop();
    if (positions.empty()) {
      rights[i] = n + 1;
    } else {
      rights[i] = positions.top();
    }
    positions.push(i);
  }
  for (int i = 1; i <= n; ++i) {
    ftIdentity.add(i, i);
  }
  vector<pair<int, int>> leftPairs;
  vector<pair<int, int>> rightPairs;
  for (int i = 1; i <= n; ++i) {
    leftPairs.push_back({lefts[i], i});
    rightPairs.push_back({i, rights[i]});
  }
  vector<query> queries(q);
  for (int i = 0; i < q; ++i) {
    cin >> queries[i].l;
    queries[i].index = i;
  }
  for (int i = 0; i < q; ++i) {
    cin >> queries[i].r;
    answer[i] = queries[i].r - queries[i].l + 1;
  }
  sort(leftPairs.begin(), leftPairs.end());
  sort(queries.begin(), queries.end(), cmpL);
  int j = (int)leftPairs.size() - 1;
  for (int i = (int)queries.size() - 1; i >= 0; --i) {
    const int L = queries[i].l;
    const int R = queries[i].r;
    const int index = queries[i].index;
    while (j >= 0 && leftPairs[j].first >= L) {
      ft.add(leftPairs[j].second, leftPairs[j].second - leftPairs[j].first - 1);
      ftIdentity.add(leftPairs[j].second, -leftPairs[j].second);
      ft01.add(leftPairs[j].second, 1);
      --j;
    }
    answer[index] += ft.sum(L, R);
    answer[index] += ftIdentity.sum(L, R);
    answer[index] -= (R - L + 1 - ft01.sum(L, R)) * L;
  }
  sort(rightPairs.begin(), rightPairs.end(), cmpRP);
  sort(queries.begin(), queries.end(), cmpR);
  ft.bit.clear();
  ft.bit.assign(n + 10, 0);
  ftIdentity.bit.clear();
  ftIdentity.bit.assign(n + 10, 0);
  ft01.bit.clear();
  ft01.bit.assign(n + 10, 0);
  for (int i = 1; i <= n; ++i) {
    ftIdentity.add(i, i);
  }
  j = 0;
  for (int i = 0; i < (int)queries.size(); ++i) {
    const int L = queries[i].l;
    const int R = queries[i].r;
    const int index = queries[i].index;
    while (j < (int)rightPairs.size() && rightPairs[j].second <= R) {
      ft.add(rightPairs[j].first,
             rightPairs[j].second - rightPairs[j].first - 1);
      ftIdentity.add(rightPairs[j].first, -rightPairs[j].first);
      ft01.add(rightPairs[j].first, 1);
      ++j;
    }
    answer[index] += ft.sum(L, R);
    answer[index] -= ftIdentity.sum(L, R);
    answer[index] += (R - L + 1 - ft01.sum(L, R)) * R;
  }
  for (int i = 0; i < q; ++i) {
    cout << answer[i] << ' ';
  }
  cout << '\n';
  return 0;
}
