#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, q, root[200005];
int sum[4000005], son[4000005][2], node;
int newnode(int x) {
  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;
}
int main() {
  n = read();
  q = read();
  for (int i = 1; i <= n; i++) {
    int x = read();
    insert(root[i], root[i - 1], 1, n, x);
  }
  int l, r, u, d;
  for (int i = 1; i <= q; i++) {
    l = read();
    d = read();
    r = read();
    u = read();
    int cnt1 = query(root[l - 1], root[0], 1, n, u + 1, n);
    int cnt2 = query(root[r], root[l - 1], 1, n, u + 1, n);
    int cnt3 = query(root[n], root[r], 1, n, u + 1, n);
    int cnt4 = query(root[l - 1], root[0], 1, n, d, u);
    int cnt5 = query(root[r], root[l - 1], 1, n, d, u);
    int cnt6 = query(root[n], root[r], 1, n, d, u);
    int cnt7 = query(root[l - 1], root[0], 1, n, 1, d - 1);
    int cnt8 = query(root[r], root[l - 1], 1, n, 1, d - 1);
    int cnt9 = 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);
  }
  return 0;
}
