#include <bits/stdc++.h>
using namespace std;
const long long N = 3 * 1e5 + 5;
const long long mod = 1e9 + 7;
const long long oo = 1e15 + 9;
long long n, q, h[N];
vector<long long> node[4 * N];
void build(long long i, long long l, long long r) {
  if (l > r) return;
  if (l == r) {
    node[i].push_back(h[l]);
    return;
  }
  long long mid = (l + r) / 2;
  build(2 * i, l, mid);
  build(2 * i + 1, mid + 1, r);
  node[i].resize(r - l + 1);
  std::merge(node[2 * i].begin(), node[2 * i].end(), node[2 * i + 1].begin(),
             node[2 * i + 1].end(), node[i].begin());
}
long long getm(long long i, long long l, long long r, long long a, long long b,
               long long pos) {
  if (a > r || l > r || b < l || a > b) return 0;
  if (a <= l && r <= b) {
    long long res =
        lower_bound(node[i].begin(), node[i].end(), pos) - node[i].begin();
    return (r - l + 1) - res;
  }
  long long mid = (l + r) / 2;
  return getm(2 * i, l, mid, a, b, pos) +
         getm(2 * i + 1, mid + 1, r, a, b, pos);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q;
  for (long long i = 1; i <= n; ++i) cin >> h[i];
  build(1, 1, n);
  while (q--) {
    long long x1, x2, y1, y2;
    cin >> y1 >> x1 >> y2 >> x2;
    long long sum = n * (n - 1) / 2;
    long long tmp = getm(1, 1, n, 1, min(y1, y2) - 1, 1);
    sum -= (tmp - 1) * tmp / 2;
    tmp = getm(1, 1, n, 1, n, 1) - getm(1, 1, n, 1, n, min(x1, x2));
    sum -= (tmp - 1) * tmp / 2;
    tmp = getm(1, 1, n, max(y1, y2) + 1, n, 1);
    sum -= (tmp - 1) * tmp / 2;
    tmp = getm(1, 1, n, 1, n, max(x1, x2) + 1);
    sum -= (tmp - 1) * tmp / 2;
    tmp = getm(1, 1, n, 1, min(y1, y2) - 1, max(x1, x2) + 1);
    sum += tmp * (tmp - 1) / 2;
    tmp = (getm(1, 1, n, 1, min(y1, y2) - 1, 1) -
           getm(1, 1, n, 1, min(y1, y2) - 1, min(x1, x2)));
    sum += tmp * (tmp - 1) / 2;
    tmp = getm(1, 1, n, max(y1, y2) + 1, n, max(x1, x2) + 1);
    sum += tmp * (tmp - 1) / 2;
    tmp = getm(1, 1, n, max(y1, y2) + 1, n, 1) -
          getm(1, 1, n, max(y1, y2) + 1, n, min(x1, x2));
    sum += tmp * (tmp - 1) / 2;
    cout << sum << '\n';
  }
}
