#include <bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
template <ostream& out = cout, class... T>
void prints(T&&...) {}
template <ostream& out = cout, class... T>
void printd(T&&...) {}
template <ostream& out = cout, class... T>
void printde(T&&...) {}
template <ostream& out = cout, class... T>
void printb(T&&...) {}
template <ostream& out = cout, class... T>
void printArr(T&&...) {}
struct BIT0 {
  vector<int> data;
  BIT0(int n) : data(n + 1) {}
  void add(int idx, int num) {
    idx++;
    for (; idx < (int)data.size(); idx += idx & -idx) {
      data[idx] += num;
    }
  }
  int sum(int idx) {
    idx++;
    int ret = 0;
    for (; idx; idx -= idx & -idx) {
      ret += data[idx];
    }
    return ret;
  }
};
struct Elem {
  int x, y, dest;
  bool operator<(const Elem& e) const { return x < e.x; }
};
ostream& operator<<(ostream& out, Elem& e) {
  out << '(' << e.x << ' ' << e.y << ')';
  return out;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  vector<int> vs(n);
  for (int i = 0; i < n; i++) {
    int p;
    cin >> p;
    p--;
    vs[i] = p;
  }
  vector<int> ls(q), ds(q), rs(q), us(q);
  vector<int> lus(q), lds(q), rus(q), rds(q);
  vector<Elem> lucs(q), ldcs(q), rucs(q), rdcs(q);
  for (int i = 0; i < q; i++) {
    cin >> ls[i] >> ds[i] >> rs[i] >> us[i];
    ls[i]--;
    ds[i]--;
    rs[i]--;
    us[i]--;
    lucs[i] = {ls[i] - 1, us[i] + 1, i};
    ldcs[i] = {ls[i] - 1, ds[i] - 1, i};
    rucs[i] = {rs[i] + 1, us[i] + 1, i};
    rdcs[i] = {rs[i] + 1, ds[i] - 1, i};
  }
  sort(lucs.begin(), lucs.end());
  sort(ldcs.begin(), ldcs.end());
  sort(rucs.begin(), rucs.end());
  sort(rdcs.begin(), rdcs.end());
  printd(lus, lds, rus, rds);
  int idx = 0;
  BIT0 bit(n);
  while (idx < q && lucs[idx].x == -1) {
    idx++;
  }
  auto in = [n](int pos) { return 0 <= pos && pos < n; };
  for (int i = 0; i < n; i++) {
    bit.add(vs[i], 1);
    while (idx < q && lucs[idx].x == i) {
      if (in(lucs[idx].y - 1)) {
        lus[lucs[idx].dest] = bit.sum(n - 1) - bit.sum(lucs[idx].y - 1);
      }
      if (in(ldcs[idx].y)) {
        lds[ldcs[idx].dest] = bit.sum(ldcs[idx].y);
      }
      idx++;
    }
  }
  printd(lus, lds, rus, rds);
  idx = q - 1;
  for (auto& i : bit.data) {
    i = 0;
  }
  while (idx >= 0 && rucs[idx].x == n) {
    idx--;
  }
  for (int i = n - 1; i >= 0; i--) {
    bit.add(vs[i], 1);
    while (idx >= 0 && rucs[idx].x == i) {
      if (in(rucs[idx].y - 1)) {
        rus[rucs[idx].dest] = bit.sum(n - 1) - bit.sum(rucs[idx].y - 1);
      }
      if (in(rdcs[idx].y)) {
        rds[rdcs[idx].dest] = bit.sum(rdcs[idx].y);
      }
      idx--;
    }
  }
  printd(lus, lds, rus, rds);
  auto f = [](ll n) { return n * (n - 1) / 2; };
  for (int i = 0; i < q; i++) {
    printd(ls[i], ds[i], n - 1 - rs[i], n - 1 - us[i], lus[i], lds[i], rus[i],
           rds[i]);
    ll num = f(ls[i]) + f(ds[i]) + f(n - 1 - rs[i]) + f(n - 1 - us[i]) -
             f(lus[i]) - f(lds[i]) - f(rus[i]) - f(rds[i]);
    cout << f(n) - num << '\n';
  }
  return 0;
}
