#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
const int MAXN = 200000;
const int MAXQ = 200000;
typedef struct Q {
  int lx, ly, hx, hy;
} Q;
typedef struct Z {
  int x, y, i, j;
} Z;
bool operator<(const Z &a, const Z &b) { return a.x < b.x; }
int n, nq;
int y[MAXN];
Q q[MAXQ];
Z z[4 * MAXQ];
int nz;
int ans[MAXQ][4];
int bt[MAXN + 1];
void bmod(int idx, int by) {
  ++idx;
  while (idx <= n) {
    bt[idx] += by;
    idx += idx & -idx;
  }
}
int bget(int idx) {
  int ret = 0;
  ++idx;
  while (idx > 0) {
    ret += bt[idx];
    idx -= idx & -idx;
  }
  return ret;
}
long long calc(int n) { return (long long)n * (n - 1) / 2; }
void run() {
  scanf("%d%d", &n, &nq);
  for (int i = (0); i < (n); ++i) scanf("%d", &y[i]), --y[i];
  for (int i = (0); i < (nq); ++i) {
    scanf("%d%d%d%d", &q[i].lx, &q[i].ly, &q[i].hx, &q[i].hy), --q[i].lx,
        --q[i].hx, --q[i].ly, --q[i].hy;
    if (q[i].lx > q[i].hx) swap(q[i].lx, q[i].hx);
    if (q[i].ly > q[i].hy) swap(q[i].ly, q[i].hy);
  }
  nz = 0;
  for (int i = (0); i < (nq); ++i) {
    int lx = q[i].lx, hx = q[i].hx, ly = q[i].ly, hy = q[i].hy;
    z[nz].x = lx - 1, z[nz].y = ly - 1, z[nz].i = i, z[nz].j = 0, ++nz;
    z[nz].x = hx, z[nz].y = ly - 1, z[nz].i = i, z[nz].j = 1, ++nz;
    z[nz].x = lx - 1, z[nz].y = hy, z[nz].i = i, z[nz].j = 2, ++nz;
    z[nz].x = hx, z[nz].y = hy, z[nz].i = i, z[nz].j = 3, ++nz;
  }
  sort(z, z + nz);
  int atz = 0;
  memset(bt, 0, sizeof(bt));
  while (atz < nz && z[atz].x == -1) ans[z[atz].i][z[atz].j] = 0, ++atz;
  for (int x = (0); x < (n); ++x) {
    bmod(y[x], +1);
    while (atz < nz && z[atz].x == x)
      ans[z[atz].i][z[atz].j] = bget(z[atz].y), ++atz;
  }
  assert(atz == nz);
  for (int i = (0); i < (nq); ++i) {
    int lx = q[i].lx, hx = q[i].hx, ly = q[i].ly, hy = q[i].hy;
    int a = ans[i][0], b = ans[i][1], c = ans[i][2], d = ans[i][3];
    long long ret = calc(n) - calc(lx) - calc(ly) - calc(n - hx - 1) -
                    calc(n - hy - 1) + calc(a) + calc(lx - c) + calc(ly - b) +
                    calc(n - (hx + 1) - (hy + 1) + d);
    printf("%lld\n", ret);
  }
}
int main() {
  run();
  return 0;
}
