#include <bits/stdc++.h>
using namespace std;
const long double PI = acosl(-1);
mt19937_64 rng(
    (unsigned)chrono::system_clock::now().time_since_epoch().count());
const int nmax = 1e6 + 5;
int perm[nmax];
long long int tree[4 * nmax];
long long int lazy[4 * nmax];
void build(int id, int l, int r) {
  lazy[id] = 0;
  if (l == r) {
    tree[id] = 0;
    return;
  }
  int mid = (l + r) >> 1;
  build((id << 1), l, mid);
  build(((id << 1) | 1), mid + 1, r);
  tree[id] = 0;
  return;
}
inline void propagate(int id, int l, int r) {
  if (l != r) {
    lazy[(id << 1)] = (lazy[(id << 1)] + lazy[id]);
    lazy[((id << 1) | 1)] = (lazy[((id << 1) | 1)] + lazy[id]);
  }
  tree[id] = (tree[id] + lazy[id] * (r - l + 1));
  lazy[id] = 0;
  return;
}
long long int query(int id, int l, int r, int L, int R) {
  if (lazy[id]) propagate(id, l, r);
  if (r < L || R < l) return 0;
  if (L <= l && r <= R) return tree[id];
  int mid = (l + r) >> 1;
  long long int p = query((id << 1), l, mid, L, R);
  long long int q = query(((id << 1) | 1), mid + 1, r, L, R);
  return p + q;
}
void update(int id, int l, int r, int L, int R, long long int v) {
  if (lazy[id]) propagate(id, l, r);
  if (r < L || R < l) return;
  if (L <= l && r <= R) {
    lazy[id] = (lazy[id] + v);
    propagate(id, l, r);
    return;
  }
  int mid = (l + r) >> 1;
  update((id << 1), l, mid, L, R, v);
  update(((id << 1) | 1), mid + 1, r, L, R, v);
  tree[id] = (tree[(id << 1)] + tree[((id << 1) | 1)]);
  return;
}
int L[nmax], R[nmax];
long long int ans[nmax];
vector<pair<int, int>> queries[nmax];
void solve(int n, int q) {
  build(1, 1, n);
  for (int i = 1; i <= n; i++) queries[i].clear();
  for (int i = 0; i < q; i++) {
    queries[R[i]].emplace_back(L[i], i);
  }
  perm[0] = n + 1;
  vector<int> stk{0};
  for (int r = 1; r <= n; r++) {
    while (perm[stk.back()] < perm[r]) stk.pop_back();
    int x = stk.back() + 1;
    stk.push_back(r);
    update(1, 1, n, x, r - 1, 1);
    for (auto p : queries[r]) {
      int l = p.first;
      int i = p.second;
      ans[i] += query(1, 1, n, l, r);
    }
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n, q;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    cin >> perm[i];
  }
  for (int i = 0; i < q; i++) cin >> L[i];
  for (int i = 0; i < q; i++) cin >> R[i];
  for (int i = 0; i < q; i++) {
    ans[i] = R[i] - L[i] + 1;
  }
  solve(n, q);
  reverse(perm + 1, perm + n + 1);
  for (int i = 0; i < q; i++) {
    L[i] = n + 1 - L[i];
    R[i] = n + 1 - R[i];
    swap(L[i], R[i]);
  }
  solve(n, q);
  for (int i = 0; i < q; i++) {
    cout << ans[i] << " ";
  }
  cout << endl;
  return 0;
}
