#include <bits/stdc++.h>
using namespace std;
const int M = 2e5 + 5;
int n, q;
int T[M], tot;
int lson[M * 40], rson[M * 40], val[M * 40];
void edit(int O, int& o, int l, int r, int pos) {
  o = ++tot;
  lson[o] = lson[O], rson[o] = rson[O];
  if (l == r) {
    val[o]++;
    return;
  }
  int m = l + r >> 1;
  if (pos <= m) edit(lson[O], lson[o], l, m, pos);
  if (pos > m) edit(rson[O], rson[o], m + 1, r, pos);
  val[o] = val[lson[o]] + val[rson[o]];
}
int curl(int O, int o, int l, int r, int L, int R) {
  if (L <= l && r <= R) return val[o] - val[O];
  int m = l + r >> 1;
  int t = 0;
  if (L <= m) t += curl(lson[O], lson[o], l, m, L, R);
  if (R > m) t += curl(rson[O], rson[o], m + 1, r, L, R);
  return t;
}
int cal(int l, int r, int d, int u) {
  int ret;
  if (l > r || d > u)
    ret = 0;
  else
    ret = curl(T[l - 1], T[r], 1, n, d, u);
  return ret;
}
long long C2(int x) { return 1LL * x * (x - 1) / 2; }
long long mul(int x, int y) { return 1LL * x * y; }
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    edit(T[i - 1], T[i], 1, n, x);
  }
  long long all = C2(n);
  while (q--) {
    int l, d, r, u;
    scanf("%d%d%d%d", &l, &d, &r, &u);
    int t1 = cal(1, l - 1, u + 1, n);
    int t2 = cal(l, r, u + 1, n);
    int t3 = cal(r + 1, n, u + 1, n);
    int t4 = cal(r + 1, n, d, u);
    int t5 = cal(r + 1, n, 1, d - 1);
    int t6 = cal(l, r, 1, d - 1);
    int t7 = cal(1, l - 1, 1, d - 1);
    int t8 = cal(1, l - 1, d, u);
    long long ans = all - C2(t1) - C2(t2) - C2(t3) - C2(t4) - C2(t5) - C2(t6) -
                    C2(t7) - C2(t8) - mul(t1, t2) - mul(t2, t3) - mul(t3, t4) -
                    mul(t4, t5) - mul(t5, t6) - mul(t6, t7) - mul(t7, t8) -
                    mul(t8, t1) - mul(t1, t3) - mul(t3, t5) - mul(t5, t7) -
                    mul(t7, t1);
    printf("%I64d\n", ans);
  }
}
