#include <bits/stdc++.h>
using namespace std;
int N, Q;
int P[1010101];
int L[1010101], R[1010101];
int Lma[1010101], Rma[1010101];
vector<int> delL[1010101], delR[1010101];
vector<int> QL[1010101], QR[1010101];
template <class V, int NV>
class SegTree_1 {
 public:
  vector<V> val;
  static V const def = 0;
  V comp(V l, V r) { return max(l, r); };
  SegTree_1() { val = vector<V>(NV * 2, def); };
  V getval(int x, int y, int l = 0, int r = NV, int k = 1) {
    if (r <= x || y <= l) return def;
    if (x <= l && r <= y) return val[k];
    return comp(getval(x, y, l, (l + r) / 2, k * 2),
                getval(x, y, (l + r) / 2, r, k * 2 + 1));
  }
  void update(int entry, V v) {
    entry += NV;
    val[entry] = comp(v, val[entry]);
    while (entry > 1)
      entry >>= 1, val[entry] = comp(val[entry * 2], val[entry * 2 + 1]);
  }
};
SegTree_1<int, 1 << 20> st;
template <class V, int ME>
class BIT {
 public:
  V bit[1 << ME];
  V operator()(int e) {
    if (e < 0) return 0;
    V s = 0;
    e++;
    while (e) s += bit[e - 1], e -= e & -e;
    return s;
  }
  void add(int e, V v) {
    e++;
    while (e <= 1 << ME) bit[e - 1] += v, e += e & -e;
  }
};
BIT<signed long long, 20> sum, mu;
signed long long ret[1010101];
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  scanf("%d%d", &N, &Q);
  for (i = 1; i <= N; i++) {
    scanf("%d", &P[i]);
    Lma[i] = st.getval(P[i], N + 1);
    delL[Lma[i]].push_back(i);
    st.update(P[i], i);
    sum.add(i, i - Lma[i]);
  }
  for (i = 0; i < (st.val.size()); i++) st.val[i] = 0;
  for (i = N; i >= 1; i--) {
    Rma[i] = N + 1 - st.getval(P[i], N + 1);
    delR[Rma[i]].push_back(i);
    st.update(P[i], N + 1 - i);
  }
  for (i = 0; i < (Q); i++) {
    scanf("%d", &L[i]);
    QL[L[i]].push_back(i);
  }
  for (i = 0; i < (Q); i++) {
    scanf("%d", &R[i]);
    QR[R[i]].push_back(i);
  }
  for (i = 0; i < (N + 1); i++) {
    for (auto& q : QL[i])
      ret[q] += (sum(R[q]) - sum(L[q] - 1)) - i * (mu(R[q]) - mu(L[q] - 1));
    for (auto& x : delL[i]) {
      sum.add(x, -(sum(x) - sum(x - 1)));
      sum.add(x, x + 1);
      mu.add(x, 1);
    }
  }
  memset(mu.bit, 0, sizeof(mu.bit));
  memset(sum.bit, 0, sizeof(sum.bit));
  for (i = 1; i <= N; i++) {
    sum.add(i, Rma[i] - i - 1);
  }
  for (i = N + 1; i >= 1; i--) {
    for (auto& q : QR[i])
      ret[q] += (sum(R[q]) - sum(L[q] - 1)) + i * (mu(R[q]) - mu(L[q] - 1));
    for (auto& x : delR[i]) {
      sum.add(x, -(sum(x) - sum(x - 1)));
      sum.add(x, -x);
      mu.add(x, 1);
    }
  }
  for (i = 0; i < (Q); i++) cout << ret[i] << " ";
  cout << endl;
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  cout.tie(0);
  solve();
  return 0;
}
