#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, q;
int p[maxn], pos[maxn];
vector<int> st[maxn];
void add(int i, int x) {
  for (; i < maxn; i += i & -i) st[i].push_back(x);
}
int get(int i, int u) {
  if (u <= 0) return 0;
  int ret = 0;
  for (; i > 0; i -= i & -i) {
    ret =
        ret + (lower_bound(st[i].begin(), st[i].end(), u + 1) - st[i].begin());
  }
  return ret;
}
long long calc(long long n) { return n * (n - 1) / 2; }
int main() {
  if (fopen("abc"
            ".inp",
            "r")) {
    freopen(
        "abc"
        ".inp",
        "r", stdin);
    freopen(
        "abc"
        ".out",
        "w", stdout);
  }
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> q;
  for (int i = 1; i <= n; ++i) {
    cin >> p[i];
    pos[p[i]] = i;
  }
  for (int i = 1; i <= n; ++i) {
    add(pos[i], i);
  }
  while (q--) {
    int l, d, r, u;
    cin >> l >> d >> r >> u;
    long long ret = calc(n);
    int A = get(l - 1, d - 1), B = get(r, d - 1) - A, C = get(n, d - 1) - A - B;
    int D = get(l - 1, u) - A, E = get(r, u) - A - B - D,
        F = get(n, u) - A - B - C - D - E;
    int G = get(l - 1, n) - A - D, H = get(r, n) - A - B - D - E - G,
        I = get(n, n) - A - B - C - D - E - F - G - H;
    ret = ret - calc(A + B + C) - calc(G + H + I) - calc(A + D + G) -
          calc(C + F + I) + calc(A) + calc(C) + calc(G) + calc(I);
    cout << ret << '\n';
  }
  return 0;
}
