#include <bits/stdc++.h>
const long long MXN = 2e5 + 4;
const long long MNN = 1e3 + 1;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const long long OO = 1e9;
using namespace std;
long long n, q, a[MXN], ans;
long long x1, rdfgjsd, x2, rdfgsd;
vector<long long> t[MXN * 4];
void Merge(long long v) {
  vector<long long> v1 = t[v * 2];
  vector<long long> v2 = t[v * 2 + 1];
  long long i = 0, j = 0;
  while (i < v1.size() && j < v2.size()) {
    if (v1[i] <= v2[j]) {
      t[v].push_back(v1[i]);
      i++;
    } else {
      t[v].push_back(v2[j]);
      j++;
    }
  }
  for (; i < v1.size(); i++) t[v].push_back(v1[i]);
  for (; j < v2.size(); j++) t[v].push_back(v2[j]);
}
void build(int v, int tl, int tr) {
  if (tl == tr) {
    t[v].push_back(a[tl]);
    return;
  }
  int tm = (tl + tr) / 2;
  build(v * 2, tl, tm);
  build(v * 2 + 1, tm + 1, tr);
  Merge(v);
}
long long get(int v, int tl, int tr, int l, int r, int L, int R) {
  if (l <= tl && tr <= r) {
    long long u = lower_bound(t[v].begin(), t[v].end(), L) - t[v].begin();
    long long g = upper_bound(t[v].begin(), t[v].end(), R) - t[v].begin();
    g--;
    return g - u + 1;
  }
  if (tl > r || tr < l) {
    return 0;
  }
  int tm = (tl + tr) / 2;
  return get(v * 2, tl, tm, l, r, L, R) +
         get(v * 2 + 1, tm + 1, tr, l, r, L, R);
}
long long sum(long long x) { return x * (x - 1) / 2; }
int main() {
  ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
  ;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    a[i] = x;
  }
  build(1, 1, n);
  while (q--) {
    cin >> x1 >> rdfgjsd >> x2 >> rdfgsd;
    ans = 0;
    long long l = x1 - 1, r = n - x2, d = n - rdfgsd, u = rdfgjsd - 1;
    ans += sum(l) + sum(r) + sum(d) + sum(u);
    long long lu = get(1, 1, n, 1, x1 - 1, 1, rdfgjsd - 1);
    long long ld = get(1, 1, n, 1, x1 - 1, rdfgsd + 1, n);
    long long rd = get(1, 1, n, x2 + 1, n, rdfgsd + 1, n);
    long long ru = get(1, 1, n, x2 + 1, n, 1, rdfgjsd - 1);
    ans -= (sum(lu) + sum(ld) + sum(rd) + sum(ru));
    cout << sum(n) - ans << '\n';
  }
  return 0;
}
