#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 6, MODM = 1e9 + 7;
struct node {
  node *L, *R;
  long long val;
  node() = default;
  node(int _val) : val(_val){};
  node(node *cpy) : val(cpy->val), L(cpy->L), R(cpy->R){};
};
typedef node *pnode;
pnode build(int tl, int tr) {
  if (tl == tr) {
    return new node(0);
  }
  int tm = (tl + tr) >> 1;
  pnode t = new node(0);
  t->L = build(tl, tm);
  t->R = build(tm + 1, tr);
  t->val = t->L->val + t->R->val;
  return t;
}
pnode update(pnode t, int pos, int new_val, int tl, int tr) {
  if (tl == tr) {
    return new node(new_val);
  }
  int tm = (tl + tr) >> 1;
  pnode res = new node(t);
  if (pos <= tm) {
    res->L = update(t->L, pos, new_val, tl, tm);
  } else {
    res->R = update(t->R, pos, new_val, tm + 1, tr);
  }
  res->val = res->L->val + res->R->val;
  return res;
}
long long get_sum(pnode t, int l, int r, int tl, int tr) {
  if (tr < l || tl > r) return 0;
  if (tl >= l && tr <= r) {
    return t->val;
  }
  int tm = (tl + tr) >> 1;
  return get_sum(t->L, l, r, tl, tm) + get_sum(t->R, l, r, tm + 1, tr);
}
long long get_c_2(long long a) { return a * (a - 1); }
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  vector<int> mas;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    mas.push_back(x);
  }
  vector<pnode> tree(n + 1);
  tree[0] = build(0, n);
  for (int i = 1; i <= n; ++i) {
    auto tmp = new node(tree[i - 1]);
    tree[i] = update(tmp, mas[i - 1], 1, 0, n);
  }
  for (int i = 0; i < q; ++i) {
    long long l, r, d, u;
    cin >> l >> d >> r >> u;
    long long res = n * 1ll * (n - 1);
    long long c1 = get_sum(tree[l - 1], 0, d - 1, 0, n);
    long long c2 = get_sum(tree[l - 1], u + 1, n, 0, n);
    long long c3 = d - 1 - get_sum(tree[r], 0, d - 1, 0, n);
    long long c4 = n - u - get_sum(tree[r], u + 1, n, 0, n);
    res += get_c_2(c1) + get_c_2(c2) + get_c_2(c3) + get_c_2(c4);
    res -= get_c_2(d - 1) + get_c_2(n - u);
    res -= get_c_2(l - 1) + get_c_2(n - r);
    cout << res / 2 << "\n";
  }
  return 0;
}
