#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 6;
long long t[maxn << 2], lz[maxn << 2];
int a[maxn], n, m;
int l[maxn], r[maxn];
vector<int> L[maxn], R[maxn];
long long ans[maxn];
int nge[maxn], pge[maxn];
void push(int u, int b, int e) {
  t[u] += lz[u] * (e - b + 1);
  if (b != e) {
    lz[u << 1] += lz[u];
    lz[u << 1 | 1] += lz[u];
  }
  lz[u] = 0;
}
void update(int u, int b, int e, int l, int r, long long val) {
  if (lz[u]) push(u, b, e);
  if (b > r or e < l) return;
  if (l <= b and e <= r) {
    lz[u] += val;
    push(u, b, e);
    return;
  }
  int mid = b + e >> 1;
  update(u << 1, b, mid, l, r, val);
  update(u << 1 | 1, mid + 1, e, l, r, val);
  t[u] = t[u << 1] + t[u << 1 | 1];
}
long long query(int u, int b, int e, int l, int r) {
  if (lz[u]) push(u, b, e);
  if (b > r or e < l) return 0;
  if (l <= b and e <= r) return t[u];
  int mid = b + e >> 1;
  return query(u << 1, b, mid, l, r) + query(u << 1 | 1, mid + 1, e, l, r);
}
int main(int argc, char const *argv[]) {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d", l + i);
    L[l[i]].emplace_back(i);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d", r + i);
    R[r[i]].emplace_back(i);
  }
  a[0] = a[n + 1] = n + 1;
  stack<int> stk;
  stk.push(0);
  for (int i = 1; i <= n; i++) {
    while (stk.size() and a[stk.top()] <= a[i]) stk.pop();
    pge[i] = stk.top();
    stk.push(i);
  }
  while (stk.size()) stk.pop();
  stk.push(n + 1);
  for (int i = n; i >= 1; i--) {
    while (stk.size() and a[stk.top()] <= a[i]) stk.pop();
    nge[i] = stk.top();
    stk.push(i);
  }
  for (int i = 1; i <= n; i++) {
    update(1, 1, n, pge[i] + 1, i, +1);
    for (int j : R[i]) {
      ans[j] += query(1, 1, n, l[j], r[j]);
    }
  }
  memset(t, 0, sizeof t);
  memset(lz, 0, sizeof lz);
  for (int i = n; i >= 1; i--) {
    update(1, 1, n, i, nge[i] - 1, +1);
    for (int j : L[i]) {
      ans[j] += query(1, 1, n, l[j], r[j]);
    }
  }
  for (int i = 1; i <= m; i++) {
    ans[i] -= (r[i] - l[i] + 1);
  }
  for (int i = 1; i <= m; i++) {
    printf("%lld ", ans[i]);
  }
  puts("");
  return 0;
}
