#include <bits/stdc++.h>
namespace global {
constexpr unsigned long n_MAX = 200000L;
unsigned long n;
}  // namespace global
namespace segment_tree {
using namespace global;
struct node {
  unsigned long sum;
  std::size_t lson, rson;
};
std::size_t cnt = 0, roots[n_MAX + 1U];
node node_pool[n_MAX << 5U];
void build(std::size_t& nd, unsigned long l, unsigned long r) {
  assert(l <= r);
  nd = cnt++;
  if (l < r) {
    unsigned long mid = (l + r) >> 1U;
    build(node_pool[nd].lson, l, mid);
    build(node_pool[nd].rson, mid + 1U, r);
  }
}
void update(std::size_t pre_nd, std::size_t& nd, unsigned long l,
            unsigned long r, unsigned long x) {
  assert(l <= x && r >= x);
  nd = cnt++;
  node_pool[nd].sum = node_pool[pre_nd].sum + 1U;
  node_pool[nd].lson = node_pool[pre_nd].lson;
  node_pool[nd].rson = node_pool[pre_nd].rson;
  if (l < r) {
    unsigned long mid = (l + r) >> 1U;
    if (x <= mid)
      update(node_pool[nd].lson, node_pool[nd].lson, l, mid, x);
    else
      update(node_pool[nd].rson, node_pool[nd].rson, mid + 1U, r, x);
  }
}
unsigned long query(std::size_t nd, unsigned long l, unsigned long r,
                    unsigned long x, unsigned long y) {
  if (x <= l && y >= r) return node_pool[nd].sum;
  unsigned long mid = (l + r) >> 1U, res = 0;
  if (mid >= x) res += query(node_pool[nd].lson, l, mid, x, y);
  if (mid < y) res += query(node_pool[nd].rson, mid + 1U, r, x, y);
  return res;
}
}  // namespace segment_tree
inline unsigned long query_rectangle(unsigned long x1, unsigned long y1,
                                     unsigned long x2, unsigned long y2) {
  using namespace global;
  using namespace segment_tree;
  if (x1 > x2 || y1 > y2) return 0;
  return query(roots[x2], 1, n, y1, y2) - query(roots[x1 - 1U], 1, n, y1, y2);
}
inline unsigned long long calc_rectangle(unsigned long x1, unsigned long y1,
                                         unsigned long x2, unsigned long y2) {
  unsigned long long tmp = query_rectangle(x1, y1, x2, y2);
  return (tmp * (tmp - 1U)) >> 1U;
}
int main() {
  using namespace global;
  using namespace segment_tree;
  unsigned long q;
  std::scanf("%lu%lu", &n, &q);
  build(roots[0], 1UL, n);
  for (unsigned long i = 1; i <= n; ++i) {
    unsigned long p;
    std::scanf("%lu", &p);
    update(roots[i - 1U], roots[i], 1, n, p);
  }
  while (q--) {
    unsigned long l, d, r, u;
    std::scanf("%lu%lu%lu%lu", &l, &d, &r, &u);
    std::printf("%llu\n", calc_rectangle(1UL, 1UL, n, n) -
                              calc_rectangle(1UL, 1UL, l - 1U, n) -
                              calc_rectangle(r + 1U, 1UL, n, n) -
                              calc_rectangle(1UL, 1UL, n, d - 1U) -
                              calc_rectangle(1UL, u + 1U, n, n) +
                              calc_rectangle(1UL, 1UL, l - 1U, d - 1U) +
                              calc_rectangle(1UL, u + 1U, l - 1U, n) +
                              calc_rectangle(r + 1U, 1UL, n, d - 1U) +
                              calc_rectangle(r + 1U, u + 1U, n, n));
  }
  return 0;
}
