#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int maxn = 2e5 + 5;
const int maxm = 35 * maxn;
int T[maxn];
int lson[maxm], rson[maxm], cnt[maxm];
int clk = 0;
void insert(int &rt, int pre, int L, int R, int pos) {
  rt = ++clk;
  lson[rt] = lson[pre];
  rson[rt] = rson[pre];
  cnt[rt] = cnt[pre] + 1;
  if (L == R) return;
  int mid = L + R >> 1;
  if (pos <= mid)
    insert(lson[rt], lson[pre], L, mid, pos);
  else
    insert(rson[rt], rson[pre], mid + 1, R, pos);
}
int query(int rt, int L, int R, int l, int r) {
  if (r < l) return 0;
  if (!rt) return 0;
  if (l <= L && R <= r)
    return cnt[rt];
  else {
    int mid = L + R >> 1;
    int ret = 0;
    if (l <= mid) ret += query(lson[rt], L, mid, l, r);
    if (mid < r) ret += query(rson[rt], mid + 1, R, l, r);
    return ret;
  }
}
int main() {
  int n, q;
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= n; i++) {
    int p;
    scanf("%d", &p);
    insert(T[i], T[i - 1], 1, n, p);
  }
  while (q--) {
    int l, d, r, u;
    scanf("%d %d %d %d", &l, &d, &r, &u);
    LL ans = 0;
    LL Buttom = query(T[n], 1, n, 1, d - 1);
    LL Top = query(T[n], 1, n, u + 1, n);
    LL Left = query(T[l - 1], 1, n, 1, n);
    LL Right = query(T[n], 1, n, 1, n) - query(T[r], 1, n, 1, n);
    LL LeftButton = query(T[l - 1], 1, n, 1, d - 1);
    LL LeftTop = query(T[l - 1], 1, n, u + 1, n);
    LL RightButton = query(T[n], 1, n, 1, d - 1) - query(T[r], 1, n, 1, d - 1);
    LL RigthTop = query(T[n], 1, n, u + 1, n) - query(T[r], 1, n, u + 1, n);
    ans += Buttom * (Buttom - 1) / 2;
    ans += Top * (Top - 1) / 2;
    ans += Left * (Left - 1) / 2;
    ans += Right * (Right - 1) / 2;
    ans -= LeftButton * (LeftButton - 1) / 2;
    ans -= LeftTop * (LeftTop - 1) / 2;
    ans -= RightButton * (RightButton - 1) / 2;
    ans -= RigthTop * (RigthTop - 1) / 2;
    ans = (LL)(n - 1) * n / 2 - ans;
    printf("%lld\n", ans);
  }
  return 0;
}
