#include <bits/stdc++.h>
using namespace std;
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
const long long maxn = 1e6 + 1e2;
long long l[maxn], r[maxn];
long long f[4 * maxn];
long long add[4 * maxn];
long long n, m;
long long a[maxn];
long long x[maxn], y[maxn];
long long ans[maxn];
void up(long long root) { f[root] = f[2 * root] + f[2 * root + 1]; }
void pushdown(long long root, long long l, long long r) {
  if (add[root]) {
    add[2 * root] += add[root];
    add[2 * root + 1] += add[root];
    long long mid = l + r >> 1;
    f[2 * root] += (mid - l + 1) * add[root];
    f[2 * root + 1] += (r - mid) * add[root];
    add[root] = 0;
  }
}
void update(long long root, long long l, long long r, long long x, long long y,
            long long p) {
  if (x > y || x == 0 || y == 0) return;
  if (x <= l && r <= y) {
    f[root] += (r - l + 1) * p;
    add[root] += p;
    return;
  }
  long long mid = l + r >> 1;
  pushdown(root, l, r);
  if (x <= mid) update(2 * root, l, mid, x, y, p);
  if (y > mid) update(2 * root + 1, mid + 1, r, x, y, p);
  up(root);
}
long long query(long long root, long long l, long long r, long long x,
                long long y) {
  if (x > y || x == 0 || y == 0) return 0;
  if (x <= l && r <= y) return f[root];
  long long mid = l + r >> 1;
  pushdown(root, l, r);
  long long ans = 0;
  if (x <= mid) ans = ans + query(2 * root, l, mid, x, y);
  if (y > mid) ans = ans + query(2 * root + 1, mid + 1, r, x, y);
  return ans;
};
struct Node {
  long long x, l, r, num, opt;
};
Node q[2 * maxn], p[maxn];
bool cmp(Node a, Node b) { return a.x < b.x; }
struct pp {
  long long val, pos;
};
pp s[maxn];
long long top;
signed main() {
  n = read(), m = read();
  for (long long i = 1; i <= n; i++) a[i] = read();
  for (long long i = 1; i <= m; i++) x[i] = read();
  for (long long i = 1; i <= m; i++) y[i] = read();
  long long cnt = 1;
  for (long long i = 1; i <= m; i++) {
    if (x[i] != 1) q[++cnt] = (Node){x[i] - 1, x[i], y[i], i, -1};
    q[++cnt] = (Node){y[i], x[i], y[i], i, 1};
  }
  sort(q + 1, q + 1 + cnt, cmp);
  l[1] = 1;
  top = 1;
  s[top].pos = 1;
  s[top].val = a[1];
  for (long long i = 2; i <= n; i++) {
    while (top >= 1 && s[top].val < a[i]) top--;
    if (!top)
      l[i] = 1;
    else
      l[i] = s[top].pos + 1;
    s[++top].val = a[i];
    s[top].pos = i;
  }
  r[n] = n;
  top = 1;
  s[top].pos = n;
  s[top].val = a[n];
  for (long long i = n - 1; i >= 1; i--) {
    while (top >= 1 && s[top].val < a[i]) top--;
    if (!top)
      r[i] = n;
    else
      r[i] = s[top].pos - 1;
    s[++top].val = a[i];
    s[top].pos = i;
  }
  for (long long i = 1; i <= n; i++) l[i]--, r[i]++;
  long long tot = 0;
  for (long long i = 1; i <= n; i++) {
    p[++tot] = (Node){i, l[i] + 1, r[i] - 1, i, 1};
  }
  sort(p + 1, p + 1 + tot, cmp);
  long long x = 1, y = 1;
  for (long long i = 1; i <= n; i++) {
    while (x <= tot && p[x].x <= i) {
      update(1, 1, n, p[x].l, p[x].r, 1);
      x++;
    }
    while (y <= cnt && q[y].x <= i) {
      ans[q[y].num] += q[y].opt * query(1, 1, n, q[y].l, q[y].r);
      y++;
    }
  }
  for (long long i = 1; i <= m; i++) cout << ans[i] << " ";
  return 0;
}
