#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 45;
const int M = 20 * N;
int q;
long long n;
int p[N], drvo[M], ls[M], rs[M], root[N], tsz;
int gde[N];
void update(int i, int j, int pos, int val, int &node, int pnode) {
  if (!node) {
    node = ++tsz;
  }
  if (i == j) {
    drvo[node] = val;
    return;
  }
  int mid = i + (j - i) / 2;
  if (pos <= mid) {
    update(i, mid, pos, val, ls[node], ls[pnode]);
    rs[node] = rs[pnode];
  } else {
    update(mid + 1, j, pos, val, rs[node], rs[pnode]);
    ls[node] = ls[pnode];
  }
  drvo[node] = drvo[ls[node]] + drvo[rs[node]];
}
int get(int i, int j, int l, int r, int nodeu, int noded) {
  if (j < l || i > r) {
    return 0;
  }
  if (l <= i && r >= j) {
    return drvo[nodeu] - drvo[noded];
  }
  int mid = i + (j - i) / 2;
  return get(i, mid, l, r, ls[nodeu], ls[noded]) +
         get(mid + 1, j, l, r, rs[nodeu], rs[noded]);
}
int marked(int l, int d, int r, int u) {
  if (l > r || d > u) {
    return 0;
  }
  return get(1, n, l, r, root[u], root[d - 1]);
}
int main() {
  scanf("%i%i", &n, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%i", &p[i]);
    gde[p[i]] = i;
  }
  for (int i = 1; i <= n; i++) {
    update(1, n, gde[i], 1, root[i], root[i - 1]);
  }
  while (q--) {
    int l, d, r, u;
    scanf("%i%i%i%i", &l, &d, &r, &u);
    long long c1 = marked(1, 1, l - 1, d - 1);
    long long c2 = marked(r + 1, 1, n, d - 1);
    long long c3 = marked(r + 1, u + 1, n, n);
    long long c4 = marked(1, u + 1, l - 1, n);
    long long uk = (n * (n - 1)) / 2;
    uk -= (c1 * (c1 - 1)) / 2;
    uk -= (c2 * (c2 - 1)) / 2;
    uk -= (c3 * (c3 - 1)) / 2;
    uk -= (c4 * (c4 - 1)) / 2;
    uk -= (c1 * c4);
    uk -= (c1 * c2);
    uk -= (c2 * c3);
    uk -= (c3 * c4);
    long long x1 = marked(1, d, l - 1, u);
    long long x2 = marked(l, 1, r, d - 1);
    long long x3 = marked(r + 1, d, n, u);
    long long x4 = marked(l, u + 1, r, n);
    uk -= (x1 * (x1 - 1)) / 2;
    uk -= (x2 * (x2 - 1)) / 2;
    uk -= (x3 * (x3 - 1)) / 2;
    uk -= (x4 * (x4 - 1)) / 2;
    uk -= x1 * c1;
    uk -= x1 * c4;
    uk -= x4 * c4;
    uk -= x4 * c3;
    uk -= x3 * c3;
    uk -= x3 * c2;
    uk -= x2 * c2;
    uk -= x2 * c1;
    printf("%lld\n", uk);
  }
}
