#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 18;
inline long long f(int k) { return 1ll * k * (k - 1) / 2; }
int n, q;
vector<int> t[2 * N];
int idxRange(int i, int d, int u) {
  int resu = upper_bound(t[i].begin(), t[i].end(), u) - t[i].begin();
  int resd = lower_bound(t[i].begin(), t[i].end(), d) - t[i].begin();
  return resu - resd;
}
int query(int l, int r, int d, int u) {
  if (d > u) return 0;
  ++r;
  int res = 0;
  for (l += N, r += N; l < r; l >>= 1, r >>= 1) {
    if (l & 1) res += idxRange(l++, d, u);
    if (r & 1) res += idxRange(--r, d, u);
  }
  return res;
}
int main() {
  scanf("%d %d", &n, &q);
  for (int i = 0, h; i < n; i++) {
    scanf("%d", &h);
    --h;
    t[N + i].push_back(h);
  }
  for (int i = N - 1; i >= 1; i--) {
    int jl = 0, jr = 0;
    while (jl < t[i << 1].size() || jr < t[i << 1 | 1].size()) {
      if (jr == t[i << 1 | 1].size() ||
          (jl < t[i << 1].size() && t[i << 1][jl] < t[i << 1 | 1][jr]))
        t[i].push_back(t[i << 1][jl++]);
      else
        t[i].push_back(t[i << 1 | 1][jr++]);
    }
  }
  for (int i = 0, l, d, r, u; i < q; i++) {
    scanf("%d %d %d %d", &l, &d, &r, &u);
    --l;
    --d;
    --r;
    --u;
    long long ans = f(n) - (f(l) + f(d) + f(n - 1 - r) + f(n - 1 - u));
    ans += f(query(0, l - 1, u + 1, n - 1));
    ans += f(query(0, l - 1, 0, d - 1));
    ans += f(query(r + 1, n - 1, u + 1, n - 1));
    ans += f(query(r + 1, n - 1, 0, d - 1));
    printf("%lld\n", ans);
  }
}
