#include <bits/stdc++.h>
inline void read(int& n) {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 1) + (x << 3) + ch - '0', ch = getchar();
  n = x * f;
}
const int N = 2e5 + 5;
struct T {
  int l, r, v;
} t[N * 30];
int n, m, p[N], cnt, a[10], root[N];
void insert(int& x, int y, int l, int r, int v) {
  x = ++cnt;
  t[x] = t[y];
  t[x].v++;
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (v <= mid)
    insert(t[x].l, t[y].l, l, mid, v);
  else
    insert(t[x].r, t[y].r, mid + 1, r, v);
}
int query(int x, int l, int r, int left, int right) {
  if (!x) return 0;
  if (left <= l && right >= r) return t[x].v;
  int mid = (l + r) >> 1;
  if (right <= mid) return query(t[x].l, l, mid, left, right);
  if (left > mid) return query(t[x].r, mid + 1, r, left, right);
  return query(t[x].l, l, mid, left, right) +
         query(t[x].r, mid + 1, r, left, right);
}
inline int query(int x1, int y1, int x2, int y2) {
  if (x1 > x2 || y1 > y2) return 0;
  return query(root[x2], 1, n, y1, y2) - query(root[x1 - 1], 1, n, y1, y2);
}
int main() {
  read(n), read(m);
  for (int i = 1; i <= n; i++)
    read(p[i]), insert(root[i], root[i - 1], 1, n, p[i]);
  while (m--) {
    int x1, y1, x2, y2;
    read(x1), read(y1), read(x2), read(y2);
    a[1] = query(1, 1, x1 - 1, y1 - 1);
    a[2] = query(1, y1, x1 - 1, y2);
    a[3] = query(1, y2 + 1, x1 - 1, n);
    a[4] = query(x1, 1, x2, y1 - 1);
    a[5] = query(x1, y2 + 1, x2, n);
    a[6] = query(x2 + 1, 1, n, y1 - 1);
    a[7] = query(x2 + 1, y1, n, y2);
    a[8] = query(x2 + 1, y2 + 1, n, n);
    long long ans = 0;
    for (int i = 1; i <= 8; i++) ans += (long long)a[i] * (a[i] - 1) / 2;
    ans += (long long)a[1] * a[2];
    ans += (long long)a[1] * a[3];
    ans += (long long)a[2] * a[3];
    ans += (long long)a[6] * a[7];
    ans += (long long)a[6] * a[8];
    ans += (long long)a[7] * a[8];
    ans += (long long)a[1] * a[4];
    ans += (long long)a[1] * a[6];
    ans += (long long)a[4] * a[6];
    ans += (long long)a[3] * a[5];
    ans += (long long)a[3] * a[8];
    ans += (long long)a[5] * a[8];
    printf("%I64d\n", (long long)n * (n - 1) / 2 - ans);
  }
  return 0;
}
