#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
vector<int> mst[4 * N];
int p[N];
void build(int l, int u, int i) {
  if (l == u) {
    mst[i].push_back(p[l]);
    return;
  }
  build(l, ((l + u) / 2), (i * 2 + 1));
  build(((l + u) / 2) + 1, u, (i * 2 + 2));
  merge(mst[(i * 2 + 1)].begin(), mst[(i * 2 + 1)].end(),
        mst[(i * 2 + 2)].begin(), mst[(i * 2 + 2)].end(),
        back_inserter(mst[i]));
}
int query(int l, int u, int i, int ll, int uu, int x) {
  if (l >= ll && u <= uu) {
    auto it = lower_bound(mst[i].begin(), mst[i].end(), x);
    int tr = it - mst[i].begin();
    return tr;
  }
  if (l > uu || u < ll) return 0;
  return query(l, ((l + u) / 2), (i * 2 + 1), ll, uu, x) +
         query(((l + u) / 2) + 1, u, (i * 2 + 2), ll, uu, x);
}
int query1(int l, int u, int i, int ll, int uu, int x) {
  if (l >= ll && u <= uu) {
    auto it = upper_bound(mst[i].begin(), mst[i].end(), x);
    int tr = it - mst[i].begin();
    return (mst[i].size() - tr);
  }
  if (l > uu || u < ll) return 0;
  return query1(l, ((l + u) / 2), (i * 2 + 1), ll, uu, x) +
         query1(((l + u) / 2) + 1, u, (i * 2 + 2), ll, uu, x);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  int q;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) cin >> p[i];
  build(1, n, 0);
  while (q--) {
    int l, r, d, u;
    cin >> l >> d >> r >> u;
    long long ans = (n * (n - 1)) / 2;
    long long ex = l - 1;
    long long rnu = query1(1, n, 0, r + 1, n, u);
    long long olu = query1(1, n, 0, 1, l - 1, u);
    long long rnd = query(1, n, 0, r + 1, n, d);
    long long old = query(1, n, 0, 1, l - 1, d);
    long long lru = query1(1, n, 0, l, r, u);
    long long lrd = query(1, n, 0, l, r, d);
    ans -= (ex * (ex - 1)) / 2;
    ex = n - r;
    ans -= (ex * (ex - 1)) / 2;
    ex = lrd;
    ans -= (ex * (ex - 1)) / 2;
    ex = lru;
    ans -= (ex * (ex - 1)) / 2;
    if (r < n) {
      ans -= (rnu * lru);
      if (l > 1) ans -= (rnu * olu);
    }
    if (l > 1) {
      ans -= (lru * olu);
    }
    if (r < n) {
      ans -= (rnd * lrd);
      if (l > 1) ans -= (rnd * old);
    }
    if (l > 1) {
      ans -= (lrd * old);
    }
    cout << ans << "\n";
  }
  return 0;
}
