#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 500;
int n, q, a[N];
struct node {
  int s, e;
  node *l, *r;
  vector<int> b;
  node() {}
  node(int *from, int *to, int lo, int hi) {
    s = lo, e = hi;
    if (s == e || from >= to) return;
    int md = (s + e) >> 1;
    auto f = [md](int x) { return x <= md; };
    b.reserve(to - from + 1);
    b.push_back(0);
    for (auto it = from; it != to; it++) b.push_back(b.back() + f(*it));
    auto pivot = stable_partition(from, to, f);
    l = new node(from, pivot, s, md);
    r = new node(pivot, to, md + 1, e);
  }
  int LTE(int l, int r, int k) {
    if (l > r || s > k) return 0;
    if (e <= k) return (r - l + 1);
    int lb = b[l - 1], rb = b[r];
    return this->l->LTE(lb + 1, rb, k) + this->r->LTE(l - lb, r - rb, k);
  }
};
node t;
int get(int c1, int r1, int c2, int r2) {
  if (r1 > r2 || c1 > c2) return 0;
  int r = t.LTE(c1, c2, r2);
  int l = t.LTE(c1, c2, r1 - 1);
  return r - l;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q;
  fill(a, a + N, 1e6);
  for (int i = 1; i <= n; i++) cin >> a[i];
  t = node(a + 1, a + n + 1, 1, n + 1);
  while (q--) {
    int c1, r1, c2, r2;
    cin >> c1 >> r1 >> c2 >> r2;
    int in = get(c1, r1, c2, r2);
    int ru = get(c2 + 1, r2 + 1, n, n);
    int r = get(c2 + 1, r1, n, r2);
    int rd = get(c2 + 1, 1, n, r1 - 1);
    int lu = get(1, r2 + 1, c1 - 1, n);
    int l = get(1, r1, c1 - 1, r2);
    int ld = get(1, 1, c1 - 1, r1 - 1);
    int up = get(c1, r2 + 1, c2, n);
    int dn = get(c1, 1, c2, r1 - 1);
    int out = n - in;
    long long ans = 0;
    ans += (in * 1ll * (in - 1)) / 2;
    ans += (in * 1ll * out);
    ans += (ru * 1ll * l) + (ru * 1ll * ld) + (ru * 1ll * dn);
    ans += (r * 1ll * up) + (r * 1ll * dn) + (r * 1ll * lu) + (r * 1ll * l) +
           (r * 1ll * ld);
    ans += (rd * 1ll * up) + (rd * 1ll * l) + (rd * 1ll * lu);
    ans += (up * 1ll * dn) + (up * 1ll * l) + (up * 1ll * ld);
    ans += (dn * 1ll * lu) + (dn * 1ll * l);
    cout << ans << '\n';
  }
}
