100 1
100 50 99 49 98 48 97 47 96 46 95 45 94 44 93 43 92 42 91 41 90 40 89 39 88 38 87 37 86 36 85 35 84 34 83 33 82 32 81 31 80 30 79 29 78 28 77 27 76 26 75 25 74 24 73 23 72 22 71 21 70 20 69 19 68 18 67 17 66 16 65 15 64 14 63 13 62 12 61 11 60 10 59 9 58 8 57 7 56 6 55 5 54 4 53 3 52 2 51 1
9 8 99 93
 2 9
1 2
1 1 1 1
1 1 1 2
1 2 1 2
1 1 2 1
1 1 2 2
1 2 2 2
2 1 2 1
2 1 2 2
2 2 2 2
 10 10
6 5 7 4 8 3 9 2 10 1
8 8 8 8
2 1 2 7
8 4 8 4
3 9 3 9
7 7 7 7
2 10 2 10
6 8 9 8
1 4 1 4
1 5 4 5
8 10 8 10
 10 10
1 10 2 9 3 8 4 7 5 6
4 3 7 10
3 6 8 7
3 2 6 4
1 1 2 8
3 8 10 9
7 3 8 9
4 5 5 9
2 5 6 7
2 5 6 7
1 7 6 10
 10 5
5 10 4 9 3 8 2 7 1 6
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
 10 10
10 9 8 7 6 5 4 3 2 1
8 8 8 8
2 1 2 7
8 4 8 4
3 9 3 9
7 7 7 7
2 10 2 10
6 8 9 8
1 4 1 4
1 5 4 5
8 10 8 10
 7 7
1 2 3 6 7 4 5
3 2 4 6
3 2 5 4
3 6 7 7
1 1 4 4
2 2 7 6
1 2 6 2
1 2 6 7
 10 10
6 1 7 2 8 3 9 4 10 5
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
 10 10
5 1 6 2 8 3 4 10 9 7
8 1 8 1
1 7 2 7
4 3 8 7
3 7 9 7
7 6 7 7
2 3 10 6
6 4 8 7
1 6 4 7
1 2 5 4
8 5 10 10
 10 10
5 6 4 7 3 8 2 9 1 10
8 8 8 8
2 1 2 7
8 4 8 4
3 9 3 9
7 7 7 7
2 10 2 10
6 8 9 8
1 4 1 4
1 5 4 5
8 10 8 10
 10 10
10 5 9 4 8 3 7 2 6 1
8 1 8 1
1 7 2 7
4 3 8 7
3 7 9 7
7 6 7 7
2 3 10 6
6 4 8 7
1 6 4 7
1 2 5 4
8 5 10 10
 10 10
7 5 1 6 10 3 4 8 9 2
4 3 7 10
3 6 8 7
3 2 6 4
1 1 2 8
3 8 10 9
7 3 8 9
4 5 5 9
2 5 6 7
2 5 6 7
1 7 6 10
 10 10
1 2 3 4 5 6 7 8 9 10
8 8 8 8
2 1 2 7
8 4 8 4
3 9 3 9
7 7 7 7
2 10 2 10
6 8 9 8
1 4 1 4
1 5 4 5
8 10 8 10
 10 10
5 1 6 2 8 3 4 10 9 7
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
 10 10
9 8 3 4 5 6 7 2 1 10
8 1 8 1
1 7 2 7
4 3 8 7
3 7 9 7
7 6 7 7
2 3 10 6
6 4 8 7
1 6 4 7
1 2 5 4
8 5 10 10
 10 10
10 1 9 2 8 3 7 4 6 5
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
1 1 10 10
 10 10
5 1 6 2 8 3 4 10 9 7
9 5 9 5
4 7 4 7
4 8 5 8
9 1 9 4
4 1 4 6
10 9 10 9
3 5 6 5
3 4 10 4
3 2 5 2
7 8 7 8
 6 10
3 6 1 2 5 4
2 6 2 6
2 3 2 5
6 2 6 2
1 5 1 5
3 5 3 5
2 2 2 4
2 4 5 4
5 4 5 4
1 5 6 5
6 2 6 2
 10 10
1 6 2 7 3 8 4 9 5 10
8 8 8 8
2 1 2 7
8 4 8 4
3 9 3 9
7 7 7 7
2 10 2 10
6 8 9 8
1 4 1 4
1 5 4 5
8 10 8 10

                                                            4886
                                                                1
                                                               1
                                                               1
                                                               1
                                                               1
                                                               1
                                                               1
                                                               1
                                                               1
                                                               11
                                                              17
                                                              15
                                                               6
                                                              16
                                                               2
                                                              19
                                                               4
                                                              20
                                                               8
                                                               39
                                                              30
                                                              26
                                                              16
                                                              23
                                                              29
                                                              27
                                                              30
                                                              30
                                                              27
                                                               45
                                                              45
                                                              45
                                                              45
                                                              45
                                                                9
                                                              14
                                                              21
                                                              16
                                                              16
                                                               9
                                                              15
                                                               4
                                                              20
                                                               3
                                                               17
                                                              16
                                                              11
                                                              16
                                                              21
                                                              11
                                                              21
                                                               45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                                3
                                                               8
                                                              37
                                                              27
                                                              21
                                                              38
                                                              29
                                                              21
                                                              23
                                                              24
                                                               16
                                                              17
                                                              12
                                                               6
                                                              16
                                                               2
                                                              23
                                                               4
                                                              20
                                                               8
                                                                8
                                                              10
                                                              38
                                                              26
                                                              21
                                                              38
                                                              31
                                                              20
                                                              21
                                                              19
                                                               38
                                                              30
                                                              25
                                                              17
                                                              24
                                                              28
                                                              29
                                                              32
                                                              32
                                                              25
                                                               23
                                                              17
                                                              12
                                                               6
                                                              27
                                                               2
                                                              23
                                                               7
                                                              24
                                                               8
                                                               45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                                8
                                                              14
                                                              38
                                                              27
                                                              19
                                                              38
                                                              29
                                                              20
                                                              23
                                                              19
                                                               45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                              45
                                                               10
                                                              16
                                                              17
                                                               8
                                                              27
                                                               2
                                                              25
                                                              26
                                                              16
                                                              16
                                                                5
                                                               9
                                                               2
                                                               2
                                                               6
                                                               8
                                                              11
                                                               8
                                                               9
                                                               2
                                                               16
                                                              17
                                                              12
                                                               6
                                                              16
                                                               2
                                                              23
                                                               7
                                                              18
                                                               8

#include <bits/stdc++.h>
inline int32_t ceil_log2np1(int32_t value) {
  assert(value >= 0);
  int32_t ax = 0;
  for (; value; value >>= 1) {
    ++ax;
  }
  return ax;
}
inline int32_t slot_index(const int32_t n) {
  int32_t ax = 0;
  int32_t j = 0;
  for (int32_t k = n; k; k >>= 1, ++j) {
    ax += (n >> (j + 1)) << j;
  }
  return ax + (n << 1);
}
inline int32_t slot_capacity(int32_t n) { return n & -n; }
inline int32_t asymptotic_total_capacity(int32_t n) {
  return n * (ceil_log2np1(n) + 1) / 2;
}
inline int32_t total_capacity(int32_t n) { return slot_index(n); }
class Ft2d {
 public:
  Ft2d(int32_t n) : m_n(n), m_c(total_capacity(n)), m_v(new int32_t[m_c]) {
    std::fill(m_v, m_v + m_c, 0);
  }
  ~Ft2d() { delete[] m_v; }
  void inc(int32_t x, int32_t y) {
    for (++y; y <= m_n; y += y & -y) {
      int32_t slot_idx = slot_index(y - 1);
      ++m_v[slot_idx];
      m_v[slot_idx + m_v[slot_idx]] = x;
    }
  }
  int32_t sum(int32_t x, int32_t y) {
    if ((x < 0) || (y < 0)) return 0;
    int32_t ax = 0;
    for (++y; y; y -= y & -y) {
      int32_t slot_idx = slot_index(y - 1);
      auto begin = m_v + slot_idx + 1;
      auto end = begin + m_v[slot_idx];
      ax += std::distance(begin, std::upper_bound(begin, end, x));
    }
    return ax;
  }

 private:
  const int32_t m_n;
  const int32_t m_c;
  int32_t* const m_v;
};
int main() {
  std::ios_base::sync_with_stdio(false);
  int64_t n, q;
  std::cin >> n >> q;
  Ft2d ft(n);
  for (int32_t k = 0; k < n; ++k) {
    int32_t row;
    std::cin >> row;
    ft.inc(k, row - 1);
  }
  for (int32_t k = 0; k < q; ++k) {
    int32_t l, d, r, u;
    std::cin >> l >> d >> r >> u;
    --l;
    --d;
    --r;
    --u;
    int64_t m[9];
    int64_t ax[9];
    ax[0] = ft.sum(l - 1, d - 1);
    ax[1] = ft.sum(r, d - 1);
    ax[2] = d;
    ax[3] = ft.sum(l - 1, u);
    ax[4] = ft.sum(r, u);
    ax[5] = u + 1;
    ax[6] = l;
    ax[7] = r + 1;
    ax[8] = n;
    m[0] = ax[0];
    m[1] = ax[1] - ax[0];
    m[2] = ax[2] - ax[1];
    m[3] = ax[3] - ax[0];
    m[4] = ax[4] - ax[3] - ax[1] + ax[0];
    m[5] = ax[5] - ax[4] - ax[2] + ax[1];
    m[6] = ax[6] - ax[3];
    m[7] = ax[7] - ax[6] - ax[4] + ax[3];
    m[8] = ax[8] - ax[7] - ax[5] + ax[4];
    auto c1 = m[0] * (m[4] + m[5] + m[7] + m[8]);
    auto c2 = m[3] * (m[1] + m[2] + m[4] + m[5] + m[7] + m[8]);
    auto c3 = m[6] * (m[1] + m[2] + m[4] + m[5]);
    auto c4 = m[1] * (m[4] + m[5] + m[7] + m[8]);
    auto c5 = m[4] * (m[2] + m[5] + m[7] + m[8]);
    auto c6 = m[7] * (m[2] + m[5]);
    auto c7 = m[4] * (m[4] - 1) / 2;
    auto count = c1 + c2 + c3 + c4 + c5 + c6 + c7;
    std::cout << count << std::endl;
  }
  return 0;
}
