#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
int size[N * 30], lc[N * 30], rc[N * 30], root[N];
int n, q, cnt;
void update(int l, int r, int &x, int last, int pos) {
  size[x = ++cnt] = size[last] + 1;
  lc[x] = lc[last];
  rc[x] = rc[last];
  if (l == r) return;
  int mid = (l + r) >> 1;
  if (pos <= mid)
    update(l, mid, lc[x], lc[last], pos);
  else
    update(mid + 1, r, rc[x], rc[last], pos);
}
int query(int l, int r, int x, int y, int a, int b) {
  if (l > b || r < a) return 0;
  if (l >= a && r <= b) return size[x] - size[y];
  int mid = (l + r) >> 1;
  return (query(l, mid, lc[x], lc[y], a, b) +
          query(mid + 1, r, rc[x], rc[y], a, b));
}
int main() {
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) {
    int x;
    scanf("%d", &x);
    update(1, n, root[i], root[i - 1], x);
  }
  while (q--) {
    int l, d, r, u;
    scanf("%d%d%d%d", &l, &d, &r, &u);
    long long ans = (long long)n * (long long)(n - 1) / 2ll, tmp;
    tmp = query(1, n, root[n], root[0], 1, d - 1);
    ans -= tmp * (tmp - 1) / 2ll;
    tmp = query(1, n, root[n], root[0], u + 1, n);
    ans -= tmp * (tmp - 1) / 2ll;
    tmp = query(1, n, root[l - 1], root[0], 1, n);
    ans -= tmp * (tmp - 1) / 2ll;
    tmp = query(1, n, root[n], root[r], 1, n);
    ans -= tmp * (tmp - 1) / 2ll;
    tmp = query(1, n, root[n], root[r], u + 1, n);
    ans += tmp * (tmp - 1) / 2ll;
    tmp = query(1, n, root[l - 1], root[0], u + 1, n);
    ans += tmp * (tmp - 1) / 2ll;
    tmp = query(1, n, root[n], root[r], 1, d - 1);
    ans += tmp * (tmp - 1) / 2ll;
    tmp = query(1, n, root[l - 1], root[0], 1, d - 1);
    ans += tmp * (tmp - 1) / 2ll;
    printf("%lld\n", ans);
  }
  return 0;
}
