#include <bits/stdc++.h>
using namespace std;
struct work {
  int l, r, val, id, type;
};
int p[200010];
int bit[200010];
long long sum[200010 * 20];
vector<work> v[200010];
int lowbit(int x) { return x & -x; }
void add(int x) {
  while (x < 200010) {
    bit[x]++;
    x += lowbit(x);
  }
}
int query(int x) {
  int ret = 0;
  while (x > 0) {
    ret += bit[x];
    x -= lowbit(x);
  }
  return ret;
}
int from[200010], to[200010], op[200010 * 20];
int main() {
  int n, q;
  scanf("%d%d", &n, &q);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &p[i]);
  }
  int idx = 0;
  for (int i = 1; i <= q; i++) {
    from[i] = idx + 1;
    int l, d, r, u;
    scanf("%d%d%d%d", &l, &d, &r, &u);
    v[n].push_back((work){u + 1, n, 1, ++idx, 1});
    v[n].push_back((work){1, d - 1, 1, ++idx, 1});
    v[l - 1].push_back((work){1, n, 1, ++idx, 1});
    v[r].push_back((work){1, n, -1, ++idx, 1});
    v[n].push_back((work){1, n, 1, idx, 1});
    v[l - 1].push_back((work){u + 1, n, 1, ++idx, -1});
    v[r].push_back((work){u + 1, n, -1, ++idx, -1});
    v[n].push_back((work){u + 1, n, 1, idx, -1});
    v[l - 1].push_back((work){1, d - 1, 1, ++idx, -1});
    v[r].push_back((work){1, d - 1, -1, ++idx, -1});
    v[n].push_back((work){1, d - 1, 1, idx, -1});
    to[i] = idx;
  }
  for (int i = 1; i <= n; i++) {
    add(p[i]);
    for (int j = 0; j < v[i].size(); j++) {
      work w = v[i][j];
      sum[w.id] += w.val * (query(w.r) - query(w.l - 1));
      op[w.id] = w.type;
    }
  }
  for (int i = 1; i <= q; i++) {
    long long ans = 1LL * n * (n - 1) / 2;
    for (int j = from[i]; j <= to[i]; j++) {
      if (op[j] == 1) {
        ans -= sum[j] * (sum[j] - 1) / 2;
      } else {
        ans += sum[j] * (sum[j] - 1) / 2;
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
