#include <bits/stdc++.h>
using namespace std;
int ls[200013 * 21], rs[200013 * 21];
int sum[200013 * 21];
int root[200100];
int tot = 0;
void pushup(int now) { sum[now] = sum[ls[now]] + sum[rs[now]]; }
void update(int pre, int &now, int l, int r, int d) {
  now = ++tot;
  ls[now] = ls[pre];
  rs[now] = rs[pre];
  sum[now] = sum[pre];
  if (l == r && l == d) {
    sum[now]++;
    return;
  }
  int mid = (l + r) >> 1;
  if (d <= mid)
    update(ls[pre], ls[now], l, mid, d);
  else
    update(rs[pre], rs[now], mid + 1, r, d);
  pushup(now);
}
int query(int l1, int r1, int L, int R, int l, int r) {
  if (L <= l && R >= r) return (sum[r1] - sum[l1]);
  int re = 0;
  int mid = (l + r) >> 1;
  if (L <= mid) re += query(ls[l1], ls[r1], L, R, l, mid);
  if (R > mid) re += query(rs[l1], rs[r1], L, R, mid + 1, r);
  return re;
}
int build(int l, int r) {
  int rot = ++tot;
  sum[rot] = 0;
  if (l == r) return rot;
  int mid = (l + r) >> 1;
  ls[rot] = build(l, mid);
  rs[rot] = build(mid + 1, r);
  return rot;
}
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  root[0] = build(1, n);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    update(root[i - 1], root[i], 1, n, x);
  }
  while (q--) {
    int l, d, r, u;
    int sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0, sum5 = 0, sum6 = 0, sum7 = 0,
        sum8 = 0, sum9 = 0;
    scanf("%d%d%d%d", &l, &d, &r, &u);
    if (d - 1 >= 1) {
      sum1 = query(root[0], root[l - 1], 1, d - 1, 1, n);
      sum2 = query(root[l - 1], root[r], 1, d - 1, 1, n);
      sum3 = query(root[r], root[n], 1, d - 1, 1, n);
    }
    sum4 = query(root[0], root[l - 1], d, u, 1, n);
    sum5 = query(root[l - 1], root[r], d, u, 1, n);
    sum6 = query(root[r], root[n], d, u, 1, n);
    sum7 = query(root[0], root[l - 1], u + 1, n, 1, n);
    sum8 = query(root[l - 1], root[r], u + 1, n, 1, n);
    sum9 = query(root[r], root[n], u + 1, n, 1, n);
    long long res = 1ll * sum1 * (1ll * sum5 + sum6 + sum8 + sum9);
    res += 1ll * sum2 * (1ll * sum4 + sum5 + sum6 + sum7 + sum8 + sum9);
    res += 1ll * sum3 * (1ll * sum4 + sum5 + sum7 + sum8);
    res += 1ll * sum4 * (1ll * sum2 + sum3 + sum5 + sum6 + sum8 + sum9);
    res += 1ll * sum5 * (n - 1);
    res += 1ll * sum6 * (1ll * sum2 + sum1 + sum4 + sum5 + sum7 + sum8);
    res += 1ll * sum7 * (1ll * sum2 + sum3 + sum5 + sum6);
    res += 1ll * sum8 * (1ll * sum1 + sum2 + sum3 + sum4 + sum5 + sum6);
    res += 1ll * sum9 * (1ll * sum1 + sum2 + sum4 + sum5);
    printf("%lld\n", res / 2);
  }
}
