#include <bits/stdc++.h>
using namespace std;
long long inline gcd(long long x, long long y) {
  return !y ? (long long)abs(x) : gcd(y, x % y);
}
long long inline lcm(long long a, long long b) {
  return ((long long)abs((a / gcd(a, b)) * b));
}
double inline cartesian_dist(double x1, double y1, double x2, double y2) {
  return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
}
long long bigmod(long long b, long long p, long long m) {
  if (!p)
    return 1 % m;
  else if (p & 1)
    return (((b % m) + m) % m * bigmod(b, p - 1, m)) % m;
  else {
    long long ret = bigmod(b, p / 2, m);
    return (ret * ret) % m;
  }
}
long long inverse(long long a, long long m) { return bigmod(a, m - 2, m); }
long long extended(long long a, long long m) {
  long long oldr = a, r = m, oldans = 1, ans = 0, quotient;
  while (r) {
    quotient = oldr / r;
    oldr = oldr - r * quotient;
    swap(oldr, r);
    oldans = oldans - ans * quotient;
    swap(oldans, ans);
  }
  return ((oldans % m) + m) % m;
}
const double PI = acos(-1.0);
const double eps = 10E-12;
long long MOD = 101LL;
int n, arr[2 * (int)1e5 + 5];
vector<int> tree[4 * 2 * (int)1e5 + 5];
void mergeTree(int i, int j, int k) {
  int a = 0, b = 0;
  while (a < tree[j].size() && b < tree[k].size())
    tree[i].push_back(tree[j][a] < tree[k][b] ? tree[j][a++] : tree[k][b++]);
  while (a < tree[j].size()) tree[i].push_back(tree[j][a++]);
  while (b < tree[k].size()) tree[i].push_back(tree[k][b++]);
}
void build(int root, int b, int e) {
  if (b == e) {
    tree[root].push_back(arr[b]);
    return;
  }
  int m = (b + e) / 2;
  build(root * 2, b, m);
  build(root * 2 + 1, m + 1, e);
  mergeTree(root, root * 2, root * 2 + 1);
}
int query(int root, int b, int e, int l, int r, int val) {
  if (b > r || e < l) return 0;
  if (b >= l && e <= r)
    return upper_bound(tree[root].begin(), tree[root].end(), val) -
           tree[root].begin();
  int m = (b + e) / 2;
  return query(root * 2, b, m, l, r, val) +
         query(root * 2 + 1, m + 1, e, l, r, val);
}
int main() {
  int q;
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= n; i++) scanf("%d", &arr[i]);
  build(1, 1, n);
  while (q--) {
    int l, d, r, u;
    scanf("%d %d", &l, &d);
    scanf("%d %d", &r, &u);
    long long ld = query(1, 1, n, 1, l - 1, d - 1);
    long long lm = query(1, 1, n, 1, l - 1, u) - ld;
    long long lu = query(1, 1, n, 1, l - 1, n) - lm - ld;
    long long md = query(1, 1, n, l, r, d - 1);
    long long mm = query(1, 1, n, l, r, u) - md;
    long long mu = query(1, 1, n, l, r, n) - mm - md;
    long long rd = query(1, 1, n, r + 1, n, d - 1);
    long long rm = query(1, 1, n, r + 1, n, u) - rd;
    long long ru = query(1, 1, n, r + 1, n, n) - rm - rd;
    long long inside = mm;
    long long outside = n - inside;
    long long res = (inside * (inside - 1LL)) / 2LL + inside * outside;
    long long urCorner = mu + ru + rm;
    long long ldCorner = lm + ld + md;
    res += urCorner * ldCorner;
    long long ulCorner = lm + lu + mu;
    long long lrCorner = md + rd + rm;
    res += ulCorner * lrCorner;
    res -= lm * rm;
    res -= mu * md;
    printf("%lld", res);
    printf("\n");
  }
  return 0;
}
