#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 2;
struct book {
  long long x1, y1, x2, y2, id;
};
long long n, q;
long long x, ans[N], node[4 * N][2];
vector<pair<long long, long long> > v;
vector<book> inp;
bool how_sort(book a, book b) { return a.y1 < b.y1; }
bool how_sort1(book a, book b) { return a.y2 > b.y2; }
long long xuli(long long a) { return a * (a - 1) / 2; }
void update(long long i, long long l, long long r, long long x,
            long long type) {
  if (l > r || x < l || r < x) return;
  if (l == r) {
    if (l == x) node[i][type] = 1;
    return;
  }
  long long mid = (l + r) / 2;
  update(i * 2, l, mid, x, type);
  update(i * 2 + 1, mid + 1, r, x, type);
  node[i][type] = node[i * 2][type] + node[i * 2 + 1][type];
}
long long get_sum(long long i, long long l, long long r, long long a,
                  long long b, long long type) {
  if (l > r || b < l || r < a) return 0LL;
  if (a <= l && r <= b) return node[i][type];
  long long mid = (l + r) / 2;
  return get_sum(i * 2, l, mid, a, b, type) +
         get_sum(i * 2 + 1, mid + 1, r, a, b, type);
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> q;
  for (long long i = 1; i <= n; ++i) {
    cin >> x;
    v.push_back(pair<long long, long long>(x, i));
  }
  sort(v.begin(), v.end());
  for (long long i = 1; i <= q; ++i) {
    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    inp.push_back(book{a, b, c, d, i});
    ans[i] += xuli(n);
    ans[i] -= xuli(a - 1);
    ans[i] -= xuli(b - 1);
    ans[i] -= xuli(n - c);
    ans[i] -= xuli(n - d);
  }
  sort(inp.begin(), inp.end(), how_sort);
  long long cur = 0;
  for (long long i = 0; i < inp.size(); ++i) {
    for (; cur < v.size() && v[cur].first < inp[i].y1; ++cur)
      update(1, 1, n, v[cur].second, 0);
    ans[inp[i].id] += xuli(get_sum(1, 1, n, 1, inp[i].x1 - 1, 0));
    ans[inp[i].id] += xuli(get_sum(1, 1, n, inp[i].x2 + 1, n, 0));
  }
  sort(inp.begin(), inp.end(), how_sort1);
  cur = n - 1;
  for (long long i = 0; i < inp.size(); ++i) {
    for (; cur >= 0 && v[cur].first > inp[i].y2; --cur)
      update(1, 1, n, v[cur].second, 1);
    ans[inp[i].id] += xuli(get_sum(1, 1, n, 1, inp[i].x1 - 1, 1));
    ans[inp[i].id] += xuli(get_sum(1, 1, n, inp[i].x2 + 1, n, 1));
  }
  for (long long i = 1; i <= q; ++i) cout << ans[i] << endl;
}
