#include <bits/stdc++.h>
using namespace std;
const int64_t INF = 1LL << 60;
const int64_t N = 1000000 + 5;
template <typename T>
class BIT {
 private:
  int64_t n;
  vector<T> arr;
  inline int64_t lowbit(int64_t x) { return x & (-x); }
  T query(int64_t x) {
    T ret = 0;
    while (x) {
      ret += arr[x];
      x -= lowbit(x);
    }
    return ret;
  }

 public:
  void init(int64_t n_) {
    n = n_;
    arr.clear();
    arr.resize(n);
  }
  void modify(int64_t p, T x) {
    while (p < n) {
      arr[p] += x;
      p += lowbit(p);
    }
  }
  T query(int64_t l, int64_t r) { return query(r) - query(l); }
};
BIT<int64_t> bit1;
BIT<int64_t> bit2;
int64_t arr[N], stk[N], qll[N], qrr[N];
pair<int64_t, int64_t> L[N], R[N], ql[N], qr[N];
int64_t ans[N];
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  int64_t n, q;
  cin >> n >> q;
  for (int64_t i = 1; i <= n; ++i) cin >> arr[i];
  for (int64_t i = 1; i <= q; ++i) cin >> qll[i];
  for (int64_t i = 1; i <= q; ++i) cin >> qrr[i];
  arr[0] = INF;
  arr[n + 1] = INF;
  {
    int64_t ptr = 0;
    stk[ptr++] = 0;
    for (int64_t i = 1; i <= n; ++i) {
      while (arr[stk[ptr - 1]] < arr[i]) ptr--;
      L[i].first = stk[ptr - 1];
      stk[ptr++] = i;
    }
  }
  {
    int64_t ptr = 0;
    stk[ptr++] = n + 1;
    for (int64_t i = n; i >= 1; --i) {
      while (arr[stk[ptr - 1]] < arr[i]) ptr--;
      R[i].first = stk[ptr - 1];
      stk[ptr++] = i;
    }
  }
  for (int64_t i = 1; i <= n; ++i) L[i].second = R[i].second = i;
  for (int64_t i = 1; i <= q; ++i) ql[i].first = qll[i];
  for (int64_t i = 1; i <= q; ++i) qr[i].first = qrr[i];
  for (int64_t i = 1; i <= q; ++i) ql[i].second = qr[i].second = i;
  sort(L + 1, L + 1 + n);
  sort(R + 1, R + 1 + n);
  reverse(L + 1, L + 1 + n);
  sort(ql + 1, ql + 1 + q);
  sort(qr + 1, qr + 1 + q);
  reverse(ql + 1, ql + 1 + q);
  {
    int64_t ptr = 1;
    bit1.init(n + 1);
    bit2.init(n + 1);
    for (int64_t i = 1; i <= q; ++i) {
      while (ptr <= n and R[ptr].first <= qr[i].first) {
        bit1.modify(R[ptr].second, R[ptr].first);
        bit2.modify(R[ptr++].second, 1);
      }
      int64_t ll = qll[qr[i].second];
      int64_t rr = qrr[qr[i].second];
      ans[qr[i].second] += bit1.query(ll - 1, rr);
      ans[qr[i].second] += (rr + 1) * (rr - ll + 1 - bit2.query(ll - 1, rr));
    }
  }
  {
    int64_t ptr = 1;
    bit1.init(n + 1);
    bit2.init(n + 1);
    for (int64_t i = 1; i <= q; ++i) {
      while (ptr <= n and L[ptr].first >= ql[i].first) {
        bit1.modify(L[ptr].second, L[ptr].first);
        bit2.modify(L[ptr++].second, 1);
      }
      int64_t ll = qll[ql[i].second];
      int64_t rr = qrr[ql[i].second];
      ans[ql[i].second] -= bit1.query(ll - 1, rr);
      ans[ql[i].second] -= (ll - 1) * (rr - ll + 1 - bit2.query(ll - 1, rr));
    }
  }
  for (int64_t i = 1; i <= q; ++i)
    cout << ans[i] - (qrr[i] - qll[i] + 1) << " \n"[i == q];
  return 0;
}
