#include <bits/stdc++.h>
using namespace std;
bool QIn(int &x) {
  char c;
  while ((c = getchar()) != EOF && !isdigit(c))
    ;
  if (c == EOF) return false;
  x = 0;
  do {
    x *= 10;
    x += c - '0';
  } while ((c = getchar()) != EOF && isdigit(c));
  return true;
}
void QOut(long long x) {
  char str[23];
  if (x) {
    int i;
    for (i = 0; x; ++i) {
      str[i] = x % 10 + '0';
      x /= 10;
    }
    while (i--) putchar(str[i]);
  } else
    putchar('0');
}
struct Node {
  int sum;
  Node *l, *r;
  Node() : sum(0), l(0), r(0) {}
};
int n, q;
Node *root[200010];
void Build(Node *&o, int L, int R) {
  o = new Node();
  if (L == R) return;
  int M = L + R >> 1;
  Build(o->l, L, M);
  Build(o->r, M + 1, R);
}
int uX, uN;
void Update(Node *&o, Node *p, int L, int R) {
  o = new Node();
  *o = *p;
  o->sum += uX;
  if (L == R) return;
  int M = L + R >> 1;
  if (uN <= M)
    Update(o->l, p->l, L, M);
  else
    Update(o->r, p->r, M + 1, R);
}
int qL, qR;
int Query(Node *lo, Node *ro, int L, int R) {
  if (qL <= L && R <= qR) return ro->sum - lo->sum;
  int M = L + R >> 1;
  int ans = 0;
  if (qL <= M) ans += Query(lo->l, ro->l, L, M);
  if (qR > M) ans += Query(lo->r, ro->r, M + 1, R);
  return ans;
}
void Add(unsigned x, unsigned y) {
  uN = y;
  uX = 1;
  Update(root[x], root[x - 1], 1, n);
}
long long Sum(unsigned x1, unsigned y1, unsigned x2, unsigned y2) {
  qL = y1;
  qR = y2;
  return Query(root[x1 - 1], root[x2], 1, n);
}
int main() {
  ios::sync_with_stdio(false);
  int p, i;
  int l, d, r, u;
  QIn(n);
  QIn(q);
  Build(root[0], 1, n);
  for (i = 1; i <= n; ++i) {
    QIn(p);
    Add(i, p);
  }
  long long ans;
  while (q--) {
    QIn(l);
    QIn(d);
    QIn(r);
    QIn(u);
    ans = 0;
    if (d > 1) {
      if (l > 1) ans += Sum(1, 1, l - 1, d - 1) * Sum(l, d, n, n);
      if (r < n) ans += Sum(r + 1, 1, n, d - 1) * Sum(1, d, r, n);
      ans += Sum(l, 1, r, d - 1) * Sum(1, d, n, n);
    }
    if (u < n) {
      if (l > 1) ans += Sum(1, u + 1, l - 1, n) * Sum(l, 1, n, u);
      if (r < n) ans += Sum(r + 1, u + 1, n, n) * Sum(1, 1, r, u);
      ans += Sum(l, u + 1, r, n) * Sum(1, 1, n, u);
    }
    if (l > 1) ans += Sum(1, d, l - 1, u) * Sum(l, 1, n, n);
    if (r < n) ans += Sum(r + 1, d, n, u) * Sum(1, 1, r, n);
    ans += Sum(l, d, r, u) * (Sum(1, 1, n, n) - 1);
    QOut(ans / 2);
    putchar('\n');
  }
  return 0;
}
