#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll N = 1 << 18;
vector<ll> t[2 * N];
ll n;
ll q;
ll cntless(ll v, ll k) {
  return (ll)(lower_bound(t[v].begin(), t[v].end(), k) - t[v].begin());
}
ll cntless(ll l, ll r, ll k) {
  ll s = 0;
  for (l += N, r += N; l <= r; l /= 2, r /= 2) {
    if (l % 2 == 1) {
      s += cntless(l++, k);
    }
    if (r % 2 == 0) {
      s += cntless(r--, k);
    }
  }
  return s;
}
ll f(ll k) { return k * (k - 1) / 2; }
signed main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> q;
  for (ll p, i = 0; i < n; ++i) {
    cin >> p;
    t[i + N] = {p};
  }
  for (ll i = N - 1; i > 0; --i) {
    t[i].resize(t[i + i].size() + t[i + i + 1].size());
    merge(t[i + i].begin(), t[i + i].end(), t[i + i + 1].begin(),
          t[i + i + 1].end(), t[i].begin());
  }
  while (q--) {
    ll l, d, r, u;
    cin >> l >> d >> r >> u;
    --l;
    --r;
    ll ans = f(l) + f(n - 1 - r) + f(cntless(1, d)) + f(n - cntless(1, u + 1));
    ans -= f(cntless(0, l - 1, d));
    ans -= f(cntless(r + 1, n - 1, d));
    ans -= f(l - cntless(0, l - 1, u + 1));
    ans -= f(n - 1 - r - cntless(r + 1, n - 1, u + 1));
    ans = f(n) - ans;
    cout << ans << "\n";
  }
  return 0;
}
