#include <bits/stdc++.h>
using namespace std;
int n, q;
inline int lowbit(int x) { return x & -x; }
struct event {
  int op, x, y1, y2, y, w, id;
} a[2100000], b[2100000];
int n1, n2;
int cmp1(event a, event b) {
  if (a.x != b.x) return a.x < b.x;
  return a.op < b.op;
}
int cmp2(event a, event b) {
  if (a.x != b.x) return a.x > b.x;
  return a.op < b.op;
}
int v[210000];
void add(int x, int y) {
  for (int i = x; i < 210000; i += lowbit(i)) v[i] += y;
}
int get(int x) {
  int res = 0;
  for (int i = x; i; i -= lowbit(i)) res += v[i];
  return res;
}
int get(int l, int r) { return get(r) - get(l - 1); }
int p[210000];
long long ans[210000];
int main() {
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
    a[++n1].x = p[i], a[n1].y = i;
    b[++n2].x = p[i], b[n2].y = i;
  }
  for (int i = 1; i <= q; i++) {
    int l, r, d, u;
    scanf("%d %d %d %d", &l, &d, &r, &u);
    a[++n1].op = 1, a[n1].x = d - 1, a[n1].y1 = 1, a[n1].y2 = n, a[n1].w = 1,
    a[n1].id = i;
    a[++n1].op = 1, a[n1].x = n, a[n1].y1 = 1, a[n1].y2 = l - 1, a[n1].w = 1,
    a[n1].id = i;
    a[++n1].op = 1, a[n1].x = n, a[n1].y1 = r + 1, a[n1].y2 = n, a[n1].w = 1,
    a[n1].id = i;
    a[++n1].op = 1, a[n1].x = d - 1, a[n1].y1 = 1, a[n1].y2 = l - 1,
    a[n1].w = -1, a[n1].id = i;
    a[++n1].op = 1, a[n1].x = d - 1, a[n1].y1 = r + 1, a[n1].y2 = n,
    a[n1].w = -1, a[n1].id = i;
    b[++n2].op = 1, b[n2].x = u + 1, b[n2].y1 = 1, b[n2].y2 = n, b[n2].w = 1,
    b[n2].id = i;
    b[++n2].op = 1, b[n2].x = u + 1, b[n2].y1 = 1, b[n2].y2 = l - 1,
    b[n2].w = -1, b[n2].id = i;
    b[++n2].op = 1, b[n2].x = u + 1, b[n2].y1 = r + 1, b[n2].y2 = n,
    b[n2].w = -1, b[n2].id = i;
  }
  sort(a + 1, a + 1 + n1, cmp1);
  for (int i = 1; i <= n1; i++) {
    if (a[i].op == 0)
      add(a[i].y, 1);
    else {
      long long num = get(a[i].y1, a[i].y2);
      ans[a[i].id] += (long long)a[i].w * ((num) * (num - 1) / 2);
    }
  }
  sort(b + 1, b + 1 + n2, cmp2);
  memset(v, 0, sizeof(v));
  for (int i = 1; i <= n2; i++) {
    if (b[i].op == 0)
      add(b[i].y, 1);
    else {
      long long num = get(b[i].y1, b[i].y2);
      ans[b[i].id] += (long long)b[i].w * ((num) * (num - 1) / 2);
    }
  }
  long long all = (long long)n * (long long)(n - 1) / 2LL;
  for (int i = 1; i <= q; i++) cout << all - ans[i] << endl;
  return 0;
}
