#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 200000, MAXLOGN = 19;
struct node {
  struct node *l, *r;
  int x;
};
struct node _node[MAXN * MAXLOGN], *nxt = _node;
int getv(struct node *cur) { return cur ? cur->x : 0; }
struct node *update(struct node *cur, int qi, int l, int r) {
  struct node *mcur = nxt++;
  if (l == r) {
    mcur->x = getv(cur) + 1;
    return mcur;
  }
  int m = (l + r) / 2;
  if (cur) {
    mcur->l = cur->l;
    mcur->r = cur->r;
  }
  if (qi <= m)
    mcur->l = update(mcur->l, qi, l, m);
  else
    mcur->r = update(mcur->r, qi, m + 1, r);
  mcur->x = getv(mcur->l) + getv(mcur->r);
  return mcur;
}
int query(struct node *cur, int ql, int qr, int l, int r) {
  if (!cur) return 0;
  if (ql <= l && r <= qr) return cur->x;
  int m = (l + r) / 2;
  int sum = 0;
  if (ql <= m) sum += query(cur->l, ql, qr, l, m);
  if (m < qr) sum += query(cur->r, ql, qr, m + 1, r);
  return sum;
}
struct node *root[MAXN + 2];
int n;
int query(int x1, int y1, int x2, int y2) {
  if (x1 > x2 || y1 > y2) return 0;
  return query(root[x2], y1, y2, 0, n) - query(root[x1 - 1], y1, y2, 0, n);
}
long long comb2(int x) { return (long long)x * (x - 1) / 2; }
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  int q;
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    int p;
    cin >> p;
    root[i] = update(root[i - 1], p, 0, n);
  }
  for (int i = 0; i < q; i++) {
    int l, d, r, u;
    cin >> l >> d >> r >> u;
    long long corner =
        comb2(query(1, u + 1, l - 1, n)) + comb2(query(r + 1, u + 1, n, n)) +
        comb2(query(1, 1, l - 1, d - 1)) + comb2(query(r + 1, 1, n, d - 1));
    long long edge =
        comb2(query(1, u + 1, n, n)) + comb2(query(1, 1, n, d - 1)) +
        comb2(query(1, 1, l - 1, n)) + comb2(query(r + 1, 1, n, n));
    long long ans = comb2(n) - edge + corner;
    cout << ans << '\n';
  }
}
