#include <bits/stdc++.h>
using namespace std;
int new_address, seg[4000005], lft[4000005], rght[4000005], root[200005];
int update(int node, int start, int end, int idx) {
  if (start > end || idx < start || end < idx) return 0;
  int nxt = ++new_address;
  if (start == end) {
    seg[nxt] = 1;
    return nxt;
  }
  int mid = (start + end) / 2;
  int l = update(lft[node], start, mid, idx);
  int r = update(rght[node], mid + 1, end, idx);
  lft[nxt] = lft[node], rght[nxt] = rght[node];
  if (l) lft[nxt] = l;
  if (r) rght[nxt] = r;
  seg[nxt] = seg[lft[nxt]] + seg[rght[nxt]];
  return nxt;
}
int query(int start, int end, int l, int r, int u, int d) {
  if (start > end || d < start || end < u) return 0;
  if (u <= start && end <= d) {
    return seg[r] - seg[l];
  }
  int mid = (start + end) / 2;
  return query(start, mid, lft[l], lft[r], u, d) +
         query(mid + 1, end, rght[l], rght[r], u, d);
}
int main() {
  int n, q, p;
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p);
    root[i] = update(root[i - 1], 1, n, p);
  }
  while (q--) {
    int l, d, r, u;
    scanf("%d%d%d%d", &l, &u, &r, &d);
    long long ans = 0;
    int a[8];
    a[0] = query(1, n, root[0], root[l - 1], 1, u - 1);
    a[2] = query(1, n, root[r], root[n], 1, u - 1);
    a[4] = query(1, n, root[r], root[n], d + 1, n);
    a[6] = query(1, n, root[0], root[l - 1], d + 1, n);
    a[1] = query(1, n, root[l - 1], root[r], 1, u - 1);
    a[3] = query(1, n, root[r], root[n], u, d);
    a[5] = query(1, n, root[l - 1], root[r], d + 1, n);
    a[7] = query(1, n, root[0], root[l - 1], u, d);
    for (int i = 0; i < 8; i++) {
      ans += 1LL * a[i] * (a[i] - 1) / 2;
    }
    ans += 1LL * a[0] * (a[1] + a[2]) + 1LL * a[1] * a[2];
    ans += 1LL * a[2] * (a[3] + a[4]) + 1LL * a[3] * a[4];
    ans += 1LL * a[4] * (a[5] + a[6]) + 1LL * a[5] * a[6];
    ans += 1LL * a[6] * (a[7] + a[0]) + 1LL * a[7] * a[0];
    printf("%lld\n", 1LL * n * (n - 1) / 2 - ans);
  }
  return 0;
}
