#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int mod = 1e9 + 7;
const int N = 2e5 + 10;
inline int add(int x, int y) {
  x += y;
  if (x >= mod) x -= mod;
  return x;
}
inline int mul(int x, int y) {
  x = (1LL * x * y) % mod;
  return x;
}
vector<int> v[6 * N];
int a[N];
int n;
void update(int curr, int i, int j) {
  if (i > j || j <= 0 || i > n) {
    return;
  }
  if (i == j) {
    v[curr].push_back(a[i]);
    return;
  }
  int c1 = curr << 1, c2 = c1 | 1, mid = (i + j) / 2;
  update(c1, i, mid);
  update(c2, mid + 1, j);
  merge(v[c1].begin(), v[c1].end(), v[c2].begin(), v[c2].end(),
        back_inserter(v[curr]));
}
int queryr(int curr, int i, int j, int x, int y, int k) {
  if (i > j || j < x || i > y) {
    return 0;
  }
  if (x <= i && j <= y) {
    return (((int)v[curr].size()) -
            (upper_bound(v[curr].begin(), v[curr].end(), k) - v[curr].begin()));
  }
  int c1 = curr << 1, c2 = c1 | 1, mid = (i + j) / 2;
  return queryr(c1, i, mid, x, y, k) + queryr(c2, mid + 1, j, x, y, k);
}
int queryl(int curr, int i, int j, int x, int y, int k) {
  if (i > j || j < x || i > y) {
    return 0;
  }
  if (x <= i && j <= y) {
    return (lower_bound(v[curr].begin(), v[curr].end(), k) - v[curr].begin());
  }
  int c1 = curr << 1, c2 = c1 | 1, mid = (i + j) / 2;
  return queryl(c1, i, mid, x, y, k) + queryl(c2, mid + 1, j, x, y, k);
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int q;
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  update(1, 1, n);
  for (int i = 1; i <= q; ++i) {
    int l, d, r, u;
    cin >> l >> u >> r >> d;
    long long ans = 1LL * n * (n - 1) / 2;
    ans -= 1LL * (u - 1) * (u - 2) / 2;
    ans -= 1LL * (n - d) * (n - d - 1) / 2;
    ans -= 1LL * (l - 1) * (l - 2) / 2;
    ans -= 1LL * (n - r) * (n - r - 1) / 2;
    int x;
    x = queryl(1, 1, n, 1, l - 1, u);
    ans += 1LL * x * (x - 1) / 2;
    x = queryr(1, 1, n, 1, l - 1, d);
    ans += 1LL * x * (x - 1) / 2;
    x = queryl(1, 1, n, r + 1, n, u);
    ans += 1LL * x * (x - 1) / 2;
    x = queryr(1, 1, n, r + 1, n, d);
    ans += 1LL * x * (x - 1) / 2;
    cout << ans << "\n";
  }
  return 0;
}
