#include <bits/stdc++.h>
int n, q;
const int MAXN = 2e5;
const int MAXQ = MAXN;
const int tree_size = MAXQ + 2;
std::vector<int> tree[tree_size * 2];
int tree_query(int node, int d, int u) {
  auto a = std::lower_bound(tree[node].begin(), tree[node].end(), d);
  if (a == tree[node].end()) return 0;
  auto b = std::upper_bound(tree[node].begin(), tree[node].end(), u);
  if (b != tree[node].begin()) {
    --b;
  }
  if (*b > u) return 0;
  int s = a - tree[node].begin();
  int e = (b == tree[node].end()) ? 0 : b - tree[node].begin();
  return e - s + 1;
}
int tree_query(int l, int d, int r, int u) {
  if (l > r || u < d) return 0;
  l += tree_size;
  r += tree_size;
  int res = tree_query(l, d, u);
  if (r != l) {
    res += tree_query(r, d, u);
  }
  while (l / 2 != r / 2) {
    if (l % 2 == 0) {
      res += tree_query(l + 1, d, u);
    }
    if (r % 2 == 1) {
      res += tree_query(r - 1, d, u);
    }
    l /= 2;
    r /= 2;
  }
  return res;
}
void insert(int column, int row) {
  column += tree_size;
  tree[column] = {row};
}
void build_tree() {
  for (int i = tree_size - 1; i > 0; --i) {
    tree[i].resize(tree[i * 2].size() + tree[i * 2 + 1].size());
    std::merge(tree[i * 2].begin(), tree[i * 2].end(), tree[i * 2 + 1].begin(),
               tree[i * 2 + 1].end(), tree[i].begin());
  }
}
long long int num_rect(long long int num) { return num * (num - 1) / 2; }
long long int query(int l, int d, int r, int u) {
  long long int whole = num_rect(n);
  int r1 = tree_query(1, 1, l - 1, d - 1);
  int r2 = l - 1;
  int r3 = tree_query(1, u + 1, l - 1, n);
  int r4 = n - u;
  int r5 = tree_query(r + 1, u + 1, n, n);
  int r6 = n - r;
  int r7 = tree_query(r + 1, 1, n, d - 1);
  int r8 = d - 1;
  return whole - num_rect(r2) - num_rect(r4) - num_rect(r6) - num_rect(r8) +
         num_rect(r1) + num_rect(r3) + num_rect(r5) + num_rect(r7);
}
void read() {
  scanf("%d %d", &n, &q);
  for (int i = 0; i < n; ++i) {
    int p;
    scanf("%d", &p);
    insert(i + 1, p);
  }
  build_tree();
  for (int i = 0; i < q; ++i) {
    int l, d, r, u;
    scanf("%d %d %d %d", &l, &d, &r, &u);
    printf("%lld\n", query(l, d, r, u));
  }
}
int main() {
  read();
  return 0;
}
