#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T& num) {
  bool start = false, neg = false;
  char c;
  num = 0;
  while ((c = getchar()) != EOF) {
    if (c == '-')
      start = neg = true;
    else if (c >= '0' && c <= '9') {
      start = true;
      num = num * 10 + c - '0';
    } else if (start)
      break;
  }
  if (neg) num = -num;
}
struct node {
  int x, y, p, v;
};
bool operator<(node a, node b) {
  if (a.x != b.x) return a.x < b.x;
  return a.y < b.y;
}
const int maxn = (int)(2e5) + 5;
int p[maxn];
long long b[maxn];
int C[maxn];
int ci[maxn * 12];
node q[maxn * 25];
vector<int> nxt[maxn];
int n, tot, idx;
inline void add(int x, int v) {
  for (; x <= n; x += ((x) & (-x))) C[x] += v;
}
inline int sum(int x) {
  int ret = 0;
  for (; x; x -= ((x) & (-x))) ret += C[x];
  return ret;
}
inline long long X(int w) { return 1LL * w * (w - 1) / 2; }
inline void addQ(int x, int y, int p, int v) { q[++tot] = (node){x, y, p, v}; }
int main() {
  int m;
  read(n);
  read(m);
  for (int i = (1); i <= (n); i++) read(p[i]);
  for (int i = (1); i <= (m); i++) {
    int l, d, r, u;
    read(l);
    read(d);
    read(r);
    read(u);
    b[i] = X(n - u) + X(d - 1) + X(l - 1) + X(n - r);
    addQ(l - 1, d - 1, ++idx, 1);
    nxt[i].push_back(idx);
    addQ(l - 1, n, ++idx, 1);
    addQ(l - 1, u, idx, -1);
    nxt[i].push_back(idx);
    addQ(n, d - 1, ++idx, 1);
    addQ(r, d - 1, idx, -1);
    nxt[i].push_back(idx);
    ci[++idx] = n;
    addQ(r, u, idx, 1);
    addQ(r, n, idx, -1);
    addQ(n, u, idx, -1);
    nxt[i].push_back(idx);
  }
  sort(q + 1, q + tot + 1);
  int ps = 1;
  for (int i = (0); i <= (n); i++) {
    if (i) add(p[i], 1);
    for (; ps <= tot && q[ps].x == i; ps++) {
      ci[q[ps].p] += q[ps].v * sum(q[ps].y);
    }
  }
  for (int i = (1); i <= (m); i++) {
    for (int j = 0; j < (int)nxt[i].size(); ++j) {
      b[i] -= X(ci[nxt[i][j]]);
    }
    printf("%I64d\n", X(n) - b[i]);
  }
  return 0;
}
