#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, Node = N * 20;
int n, q, root[N];
struct SegmentTree {
  int sum[Node], son[Node][2], node;
  int newnode(int x) {
    ++node;
    sum[node] = sum[x];
    son[node][0] = son[x][0];
    son[node][1] = son[x][1];
    return node;
  }
  void Insert(int &z, int x, int l, int r, int pos) {
    z = newnode(x);
    sum[z]++;
    if (l == r) return;
    int mid = (l + r) >> 1;
    if (pos <= mid)
      Insert(son[z][0], son[x][0], l, mid, pos);
    else
      Insert(son[z][1], son[x][1], mid + 1, r, pos);
  }
  int Query(int rs, int ls, int l, int r, int ql, int qr) {
    if (ql > qr) return 0;
    if (ql <= l && r <= qr) return sum[rs] - sum[ls];
    int mid = (l + r) >> 1, ret = 0;
    if (ql <= mid) ret += Query(son[rs][0], son[ls][0], l, mid, ql, qr);
    if (qr > mid) ret += Query(son[rs][1], son[ls][1], mid + 1, r, ql, qr);
    return ret;
  }
} St;
void Init() {
  scanf("%d%d", &n, &q);
  int x;
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &x);
    St.Insert(root[i], root[i - 1], 1, n, x);
  }
}
void Solve() {
  int l, r, u, d;
  for (int i = 1; i <= q; ++i) {
    scanf("%d%d%d%d", &l, &d, &r, &u);
    int cnt1 = St.Query(root[l - 1], root[0], 1, n, u + 1, n);
    int cnt2 = St.Query(root[r], root[l - 1], 1, n, u + 1, n);
    int cnt3 = St.Query(root[n], root[r], 1, n, u + 1, n);
    int cnt4 = St.Query(root[l - 1], root[0], 1, n, d, u);
    int cnt5 = St.Query(root[r], root[l - 1], 1, n, d, u);
    int cnt6 = St.Query(root[n], root[r], 1, n, d, u);
    int cnt7 = St.Query(root[l - 1], root[0], 1, n, 1, d - 1);
    int cnt8 = St.Query(root[r], root[l - 1], 1, n, 1, d - 1);
    int cnt9 = St.Query(root[n], root[r], 1, n, 1, d - 1);
    long long ans = 0;
    ans += 1ll * cnt1 * (cnt5 + cnt6 + cnt8 + cnt9);
    ans += 1ll * cnt2 * (cnt4 + cnt5 + cnt6 + cnt7 + cnt8 + cnt9);
    ans += 1ll * cnt3 * (cnt4 + cnt5 + cnt7 + cnt8);
    ans += 1ll * cnt4 * (cnt2 + cnt3 + cnt5 + cnt6 + cnt8 + cnt9);
    ans += 1ll * cnt5 * (n - 1);
    ans += 1ll * cnt6 * (cnt1 + cnt2 + cnt4 + cnt5 + cnt7 + cnt8);
    ans += 1ll * cnt7 * (cnt2 + cnt3 + cnt5 + cnt6);
    ans += 1ll * cnt8 * (cnt1 + cnt2 + cnt3 + cnt4 + cnt5 + cnt6);
    ans += 1ll * cnt9 * (cnt1 + cnt2 + cnt4 + cnt5);
    printf("%I64d\n", ans / 2);
  }
}
int main() {
  Init();
  Solve();
  return 0;
}
