#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long INFF = 0x3f3f3f3f3f3f3f3fll;
const int MAX = 2e5 + 5;
const int MAXN = 1000000;
const int MAX_N = MAX;
const long long MOD = 1e9 + 7;
const long double pi = acos(-1.0);
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
template <typename T>
inline T abs(T a) {
  return a > 0 ? a : -a;
}
template <class T>
inline void read(T& num) {
  bool start = false, neg = false;
  char c;
  num = 0;
  while ((c = getchar()) != EOF) {
    if (c == '-')
      start = neg = true;
    else if (c >= '0' && c <= '9') {
      start = true;
      num = num * 10 + c - '0';
    } else if (start)
      break;
  }
  if (neg) num = -num;
}
inline long long powMM(long long a, long long b, long long M) {
  long long ret = 1;
  a %= M;
  while (b) {
    if (b & 1) ret = ret * a % M;
    b >>= 1;
    a = a * a % M;
  }
  return ret;
}
void open() {
  freopen("1009.in", "r", stdin);
  freopen("out.txt", "w", stdout);
}
int ls[MAX * 40], rs[MAX * 40], sum[MAX * 40], rt[MAX];
int num;
long long ld, lp, lu, u, ru, rp, rd, re, d, tot;
void build(int& now, int pre, int pos, int l, int r) {
  now = ++num;
  ls[now] = ls[pre];
  rs[now] = rs[pre];
  sum[now] = sum[pre] + 1;
  if (l == r) return;
  int mid = (l + r) / 2;
  if (pos <= mid)
    build(ls[now], ls[pre], pos, l, mid);
  else
    build(rs[now], rs[pre], pos, mid + 1, r);
}
int query(int now, int l, int r, int ql, int qr) {
  if (!now || ql <= l && qr >= r) return sum[now];
  int mid = (l + r) / 2;
  if (mid < ql)
    return query(rs[now], mid + 1, r, ql, qr);
  else if (mid >= qr)
    return query(ls[now], l, mid, ql, qr);
  else
    return query(ls[now], l, mid, ql, qr) + query(rs[now], mid + 1, r, ql, qr);
}
int n, q;
inline int cnt(int xs, int ys, int xe, int ye) {
  if (xs > xe || ys > ye) return 0;
  return query(rt[xe], 1, n, ys, ye) - query(rt[xs - 1], 1, n, ys, ye);
}
long long solve(int sx, int sy, int ex, int ey) {
  lp = cnt(1, sy, sx - 1, ey);
  rp = cnt(ex + 1, sy, n, ey);
  ld = cnt(1, 1, sx - 1, sy - 1);
  rd = cnt(ex + 1, 1, n, sy - 1);
  lu = cnt(1, ey + 1, sx - 1, n);
  ru = cnt(ex + 1, ey + 1, n, n);
  d = cnt(sx, 1, ex, sy - 1);
  u = cnt(sx, ey + 1, ex, n);
  re = ld * (lp + lu + d + rd) + ru * (u + lu + rp + rd) + lp * lu + d * rd +
       u * lu + rp * rd;
  re += lp * (lp - 1) / 2 + (rp - 1) * rp / 2 + (ld - 1) * ld / 2 +
        (rd - 1) * rd / 2 + lu * (lu - 1) / 2 + (ru - 1) * ru / 2 +
        d * (d - 1) / 2 + u * (u - 1) / 2;
  return tot - re;
}
int tem, sx, sy, ex, ey;
int main() {
  scanf("%d%d", &n, &q);
  tot = 1LL * n * (n - 1LL) / 2;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &tem);
    build(rt[i], rt[i - 1], tem, 1, n);
  }
  for (int i = 1; i <= q; i++) {
    scanf("%d%d%d%d", &sx, &sy, &ex, &ey);
    printf("%I64d\n", solve(sx, sy, ex, ey));
  }
}
