#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 1;
int n, q, c[9];
vector<int> iman[maxn];
void majid(int p, int y) {
  for (p++; p < maxn; p += p & -p) iman[p].push_back(y);
}
int hamid(int p, int y) {
  int ans = 0;
  for (; p; p ^= p & -p)
    ans += lower_bound(iman[p].begin(), iman[p].end(), y) - iman[p].begin();
  return ans;
}
int main() {
  scanf("%d%d", &n, &q);
  for (int i = 0; i < n; i++) {
    int y;
    scanf("%d", &y), y--;
    majid(i, y);
  }
  for (int i = 0; i < maxn; i++) sort(iman[i].begin(), iman[i].end());
  while (q--) {
    int l, d, r, u;
    scanf("%d%d%d%d", &l, &d, &r, &u);
    l--, d--;
    c[6] = hamid(l, d);
    c[7] = hamid(r, d) - c[6];
    c[8] = d - c[6] - c[7];
    c[3] = hamid(l, u) - c[6];
    c[4] = hamid(r, u) - c[6] - c[3] - c[7];
    c[5] = u - c[4] - c[3] - c[8] - c[7] - c[6];
    c[0] = l - c[3] - c[6];
    c[1] = r - l - c[4] - c[7];
    c[2] = n - r - c[5] - c[8];
    long long ans = 0;
    ans += (long long)c[0] * (c[4] + c[7] + c[5] + c[8]);
    ans += (long long)c[1] * u;
    ans += (long long)c[2] * (c[3] + c[4] + c[6] + c[7]);
    ans += (long long)c[3] * (c[4] + c[5] + c[7] + c[8]);
    int cen = c[4];
    ans += (long long)cen * (u - c[3]) - (long long)cen * (cen + 1) / 2;
    ans += (long long)c[5] * (d - c[8]);
    printf("%lld\n", ans);
  }
  return 0;
}
