#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
std::vector<int> sum[maxn];
int n, q;
void update(int x, int i) {
  while (x <= n) {
    sum[x].push_back(i);
    x += (x & (-x));
  }
}
int query(int x, int y) {
  int ans = 0;
  while (x) {
    ans += lower_bound(sum[x].begin(), sum[x].end(), y + 1) - sum[x].begin();
    x -= (x & (-x));
  }
  return ans;
}
long long calc(int x) { return 1ll * x * (x - 1) / 2; }
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(false);
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    int p;
    cin >> p;
    update(p, i);
  }
  int l, d, r, u;
  while (q--) {
    cin >> l >> d >> r >> u;
    int A = query(d - 1, l - 1);
    int B = query(d - 1, r) - A;
    int C = query(d - 1, n) - A - B;
    int D = query(u, l - 1) - A;
    int E = query(u, r) - A - B - D;
    int F = query(u, n) - A - B - C - D - E;
    int G = query(n, l - 1) - A - D;
    int H = query(n, r) - A - B - D - E - G;
    int I = n - A - B - C - D - E - F - G - H;
    long long res = calc(n) - calc(A + B + C) - calc(A + D + G) -
                    calc(G + H + I) - calc(C + F + I) + calc(A) + calc(G) +
                    calc(I) + calc(C);
    cout << res << endl;
  }
  return 0;
}
