#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
const long long linf = 1e18;
const int N = 2 * 100000 + 10;
long long n;
int m;
int a[N];
int pos[N];
struct query {
  int l, d, r, u;
} q[N];
struct query2 {
  int l, d, r, u;
  int bel;
  long long val;
} Q[4 * N];
int o;
struct info {
  int x, y;
  int bel;
  int sign;
  long long val;
} b[16 * N];
int p;
int c[N];
long long ans[N];
long long sum1[N], sum2[N], sum3[N], sum4[N];
int lowbit(int x) { return x & -x; }
int sum(int x) {
  int res = 0;
  while (x >= 1) {
    res += c[x];
    x -= lowbit(x);
  }
  return res;
}
void add(int x, int v) {
  while (x <= n) {
    c[x] += v;
    x += lowbit(x);
  }
}
bool cmp(info a, info b) { return a.y < b.y; }
int main() {
  std::ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++)
    sum1[i] = sum3[i] = i, sum2[i] = sum4[i] = n - i + 1;
  for (int i = 1; i <= n; i++) pos[a[i]] = i;
  for (int i = 1; i <= m; i++) cin >> q[i].l >> q[i].u >> q[i].r >> q[i].d;
  for (int i = 1; i <= m; i++) {
    int l = q[i].l, r = q[i].r, u = q[i].u, d = q[i].d;
    if (l >= 1 && u >= 1)
      Q[++o].l = 1, Q[o].r = l - 1, Q[o].u = 1, Q[o].d = u - 1, Q[o].bel = i;
    if (r <= n && u >= 1)
      Q[++o].l = r + 1, Q[o].r = n, Q[o].u = 1, Q[o].d = u - 1, Q[o].bel = i;
    if (l >= 1 && d <= n)
      Q[++o].l = 1, Q[o].r = l - 1, Q[o].u = d + 1, Q[o].d = n, Q[o].bel = i;
    if (r <= n && d <= n)
      Q[++o].l = r + 1, Q[o].r = n, Q[o].u = d + 1, Q[o].d = n, Q[o].bel = i;
  }
  for (int i = 1; i <= o; i++) {
    int l = Q[i].l, r = Q[i].r, u = Q[i].u, d = Q[i].d;
    b[++p].x = r, b[p].y = d, b[p].bel = i, b[p].sign = 1;
    b[++p].x = l - 1, b[p].y = u - 1, b[p].bel = i, b[p].sign = 1;
    b[++p].x = l - 1, b[p].y = d, b[p].bel = i, b[p].sign = -1;
    b[++p].x = r, b[p].y = u - 1, b[p].bel = i, b[p].sign = -1;
  }
  sort(b + 1, b + 1 + p, cmp);
  int now = 1;
  for (int i = 1; i <= n + 1; i++) {
    while (now <= p && b[now].y < i) {
      b[now].val = sum(b[now].x);
      now++;
    }
    if (i == n + 1) break;
    add(pos[i], 1);
  }
  for (int i = 1; i <= p; i++) Q[b[i].bel].val += b[i].sign * b[i].val;
  for (int i = 1; i <= o; i++) ans[Q[i].bel] -= Q[i].val * (Q[i].val - 1) / 2;
  for (int i = 1; i <= m; i++) {
    ans[i] += sum1[q[i].u - 1] * (sum1[q[i].u - 1] - 1) / 2;
    ans[i] += sum2[q[i].d + 1] * (sum2[q[i].d + 1] - 1) / 2;
    ans[i] += sum3[q[i].l - 1] * (sum3[q[i].l - 1] - 1) / 2;
    ans[i] += sum4[q[i].r + 1] * (sum4[q[i].r + 1] - 1) / 2;
    cout << n * (n - 1) / 2 - ans[i] << endl;
  }
  return 0;
}
