#include <bits/stdc++.h>
using namespace std;
int n, q;
int p[200005];
vector<int> tree[4 * 200005];
void build(int node, int a, int b) {
  if (a == b) {
    tree[node].push_back(p[a]);
    return;
  }
  build(node * 2, a, (a + b) / 2);
  build(node * 2 + 1, 1 + (a + b) / 2, b);
  int i = 0, j = 0;
  while (i < tree[node * 2].size() || j < tree[node * 2 + 1].size()) {
    if (i == tree[node * 2].size()) {
      tree[node].push_back(tree[node * 2 + 1][j]);
      ++j;
    } else if (j == tree[node * 2 + 1].size()) {
      tree[node].push_back(tree[node * 2][i]);
      ++i;
    } else if (tree[node * 2][i] < tree[node * 2 + 1][j]) {
      tree[node].push_back(tree[node * 2][i]);
      ++i;
    } else {
      tree[node].push_back(tree[node * 2 + 1][j]);
      ++j;
    }
  }
}
int que(int node, int a, int b, int i, int j, int q, bool up) {
  if (a > j || b < i || a > b) return 0;
  if (i <= a && b <= j) {
    if (!up) {
      int ans = lower_bound(tree[node].begin(), tree[node].end(), q) -
                tree[node].begin();
      return ans;
    } else {
      int ans = tree[node].end() -
                upper_bound(tree[node].begin(), tree[node].end(), q);
      return ans;
    }
  }
  int q1 = que(node * 2, a, (a + b) / 2, i, j, q, up);
  int q2 = que(node * 2 + 1, 1 + (a + b) / 2, b, i, j, q, up);
  return q1 + q2;
}
long long c2(long long x) { return x * (x - 1) / 2; }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> q;
  for (long long i = (1); i <= (signed)(n); i++) cin >> p[i];
  build(1, 1, n);
  for (long long i = 0; i < (signed)(q); i++) {
    int u, d, l, r;
    cin >> l >> d >> r >> u;
    long long cur = c2(l - 1) + c2(d - 1) + c2(n - r) + c2(n - u);
    cur -= c2(que(1, 1, n, 1, l - 1, d, false));
    cur -= c2(que(1, 1, n, 1, l - 1, u, true));
    cur -= c2(que(1, 1, n, r + 1, n, d, false));
    cur -= c2(que(1, 1, n, r + 1, n, u, true));
    cout << c2(n) - cur << "\n";
  }
  return 0;
}
