#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int l[30 * maxn], r[30 * maxn], sz[30 * maxn];
int tot = 0, t[maxn], p[maxn];
int build(int le, int ri) {
  int root = tot++;
  sz[root] = 0;
  int m = (le + ri) >> 1;
  if (le != ri) {
    l[root] = build(le, m);
    r[root] - build(m + 1, ri);
  }
  return root;
}
int update(int root, int le, int ri, int x, int k) {
  int now = tot++;
  sz[now] = sz[root] + k;
  if (le == ri) return now;
  int m = (le + ri) >> 1;
  if (x <= m) {
    l[now] = update(l[root], le, m, x, k);
    r[now] = r[root];
  } else {
    r[now] = update(r[root], m + 1, ri, x, k);
    l[now] = l[root];
  }
  return now;
}
int query(int root, int le, int ri, int L, int R) {
  if (L > R) return 0;
  if (L <= le && R >= ri) {
    return sz[root];
  }
  if (le == ri) {
    return sz[root];
  }
  int sum = 0;
  int m = (le + ri) >> 1;
  if (m >= L) {
    sum += query(l[root], le, m, L, R);
  }
  if (m < R) {
    sum += query(r[root], m + 1, ri, L, R);
  }
  return sum;
}
inline long long f(int x) { return 1ll * x * (x - 1) / 2; }
int main() {
  int i, n, q, l, r, u, d;
  cin >> n >> q;
  t[0] = build(1, n);
  for (i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
    t[i] = update(t[i - 1], 1, n, p[i], 1);
  }
  long long ans = 0;
  while (q--) {
    ans = f(n);
    scanf("%d %d %d %d", &l, &d, &r, &u);
    int temp1 = query(t[n], 1, n, 1, n) - query(t[r], 1, n, 1, n);
    int temp2 = query(t[n], 1, n, u + 1, n);
    int temp3 = temp2 - query(t[r], 1, n, u + 1, n);
    int temp4 = query(t[l - 1], 1, n, 1, n);
    int temp5 = query(t[n], 1, n, 1, d - 1);
    int temp6 = temp5 - query(t[r], 1, n, 1, d - 1);
    int temp7 = temp4 - query(t[l - 1], 1, n, 1, u);
    int temp8 = query(t[l - 1], 1, n, 1, d - 1);
    ans -= f(temp1) + f(temp2) + f(temp4) + f(temp5) - f(temp3) - f(temp7) -
           f(temp8) - f(temp6);
    printf("%I64d\n", ans);
  }
  return 0;
}
