#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline void read(T &x) {
  x = 0;
  T fl = 1;
  char ch = 0;
  for (; ch < '0' || ch > '9'; ch = getchar())
    if (ch == '-') fl = -1;
  for (; ch >= '0' && ch <= '9'; ch = getchar())
    x = (x << 1) + (x << 3) + (ch ^ 48);
  x *= fl;
}
const int N = 500000 + 6;
long long rt[N];
namespace seg {
long long tot = 0;
struct node {
  long long lc, rc, s;
} tr[N * 10];
void ins(long long &nod, long long pre, long long l, long long r, long long x) {
  nod = ++tot;
  tr[nod].s = tr[pre].s + 1;
  tr[nod].rc = tr[pre].rc;
  tr[nod].lc = tr[pre].lc;
  if (l == r) return;
  long long mid = (l + r) >> 1;
  if (x <= mid)
    ins(tr[nod].rc, tr[pre].rc, l, mid, x);
  else
    ins(tr[nod].lc, tr[pre].lc, mid + 1, r, x);
}
long long query(long long nod, long long pre, long long l, long long r,
                long long ql, long long qr) {
  if (ql <= l && r <= qr) return tr[pre].s - tr[nod].s;
  long long mid = (l + r) >> 1;
  if (qr <= mid)
    return query(tr[nod].rc, tr[pre].rc, l, mid, ql, qr);
  else if (ql > mid)
    return query(tr[nod].lc, tr[pre].lc, mid + 1, r, ql, qr);
  else
    return query(tr[nod].rc, tr[pre].rc, l, mid, ql, mid) +
           query(tr[nod].lc, tr[pre].lc, mid + 1, r, mid + 1, qr);
}
}  // namespace seg
long long C2(long long x) { return 1ll * x * (x - 1) / 2; }
long long n, m;
int main() {
  read(n);
  read(m);
  for (int i = 1; i <= n; i++) {
    long long x;
    read(x);
    seg::ins(rt[i], rt[i - 1], 1, n, x);
  }
  while (m--) {
    long long ans = C2(n), l, d, r, u, x, y;
    read(l);
    read(d);
    read(r);
    read(u);
    ans -= C2(l - 1) + C2(n - r) + C2(d - 1) + C2(n - u);
    x = d > 1 ? seg::query(rt[0], rt[l - 1], 1, n, 1, d - 1) : 0;
    y = u < n ? seg::query(rt[0], rt[l - 1], 1, n, u + 1, n) : 0;
    ans += C2(x) + C2(y);
    x = d > 1 ? seg::query(rt[r], rt[n], 1, n, 1, d - 1) : 0;
    y = u < n ? seg::query(rt[r], rt[n], 1, n, u + 1, n) : 0;
    ans += C2(x) + C2(y);
    printf("%lld\n", ans);
  }
  return 0;
}
