#include <bits/stdc++.h>
using namespace std;
const int maxn = 202020;
int a[maxn];
struct Query {
  int tp, x, l, r, id;
  bool operator<(Query b) const {
    if (x != b.x) {
      return x < b.x;
    }
    return tp < b.tp;
  }
} q[2 * maxn];
struct Rectangle {
  int l, r, d, u;
  void in() { cin >> l >> d >> r >> u; }
} r[maxn];
int b[maxn];
int n;
inline void upd(int r, int val) {
  for (; r <= n; r = (r | (r + 1))) {
    a[r] += val;
  }
}
inline int get(int r) {
  int ans = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) {
    ans += a[r];
  }
  return ans;
}
long long bonus[maxn];
inline long long f(int n) { return n * 1ll * (n - 1) / 2; }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie();
  int p;
  cin >> n >> p;
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  for (int i = 1; i <= p; i++) {
    r[i].in();
  }
  int sz = 0;
  for (int i = 1; i <= n; i++) {
    sz++;
    q[sz].tp = 1;
    q[sz].x = b[i];
    q[sz].id = i;
  }
  for (int i = 1; i <= p; i++) {
    sz++;
    q[sz].tp = 0;
    q[sz].l = r[i].l, q[sz].r = r[i].r;
    q[sz].id = i;
    q[sz].x = r[i].d;
  }
  sort(q + 1, q + sz + 1);
  int rem;
  for (int i = 1; i <= sz; i++) {
    if (!q[i].tp) {
      rem = get(q[i].l - 1);
      bonus[q[i].id] += f(rem);
      rem = get(n) - get(q[i].r);
      bonus[q[i].id] += f(rem);
    } else {
      upd(q[i].id, 1);
    }
  }
  memset(a, 0, sizeof(a));
  sz = 0;
  for (int i = 1; i <= n; i++) {
    sz++;
    q[sz].tp = 0;
    q[sz].x = b[i];
    q[sz].id = i;
  }
  for (int i = 1; i <= p; i++) {
    sz++;
    q[sz].tp = 1;
    q[sz].l = r[i].l, q[sz].r = r[i].r;
    q[sz].id = i;
    q[sz].x = r[i].u;
  }
  sort(q + 1, q + sz + 1);
  for (int i = sz; i >= 1; i--) {
    if (q[i].tp) {
      rem = get(q[i].l - 1);
      bonus[q[i].id] += f(rem);
      rem = get(n) - get(q[i].r);
      bonus[q[i].id] += f(rem);
    } else {
      upd(q[i].id, 1);
    }
  }
  for (int i = 1; i <= p; i++) {
    cout << f(n) - f(r[i].l - 1) - f(r[i].d - 1) - f(n - r[i].r) -
                f(n - r[i].u) + bonus[i]
         << endl;
  }
  return 0;
}
