#include <bits/stdc++.h>
using namespace std;
int n;
int arr[200003];
vector<int> tree[800003];
void merge(int pos, int a, int b) {
  int l1 = 0, l2 = 0;
  while (l1 < tree[a].size() || l2 < tree[b].size()) {
    if (l1 == tree[a].size())
      tree[pos].push_back(tree[b][l2++]);
    else if (l2 == tree[b].size())
      tree[pos].push_back(tree[a][l1++]);
    else {
      if (tree[a][l1] < tree[b][l2])
        tree[pos].push_back(tree[a][l1++]);
      else
        tree[pos].push_back(tree[b][l2++]);
    }
  }
}
void build(int pos, int kir, int kan) {
  if (kir == kan) {
    tree[pos].push_back(arr[kir]);
    return;
  }
  int mid = (kir + kan) / 2;
  build(pos * 2, kir, mid);
  build(pos * 2 + 1, mid + 1, kan);
  merge(pos, pos * 2, pos * 2 + 1);
}
long long f(int n) { return (1LL * n) * (1LL * n - 1) / 2; }
void print() {
  for (int i = 1; i <= 1000; i++) {
    if (tree[i].empty())
      break;
    else {
      printf("i : %d\n", i);
      for (int j : tree[i]) printf("%d ", j);
      printf("\n");
    }
  }
}
int query(int pos, int kir, int kan, int qkir, int qkan, int qdo, int qup) {
  if (qkir > kan || kir > qkan)
    return 0;
  else if (qkir <= kir && kan <= qkan) {
    int l, r;
    if (qdo > tree[pos].back()) return 0;
    if (qup < tree[pos][0]) return 0;
    l = 0;
    r = tree[pos].size() - 1;
    while (l < r) {
      int mid = (l + r) / 2;
      if (tree[pos][mid] < qdo)
        l = mid + 1;
      else
        r = mid;
    }
    int temp = l;
    l = 0;
    r = tree[pos].size() - 1;
    while (l < r) {
      int mid = (l + r + 1) / 2;
      if (tree[pos][mid] > qup)
        r = mid - 1;
      else
        l = mid;
    }
    return r - temp + 1;
  } else {
    int mid = (kir + kan) / 2;
    return query(pos * 2, kir, mid, qkir, qkan, qdo, qup) +
           query(pos * 2 + 1, mid + 1, kan, qkir, qkan, qdo, qup);
  }
}
int query(int kir, int kan, int baw, int ata) {
  return query(1, 1, n, kir, kan, baw, ata);
}
int main() {
  int q;
  scanf("%d %d", &n, &q);
  for (int i = 1; i <= n; i++) scanf("%d", &arr[i]);
  build(1, 1, n);
  while (q--) {
    int l, d, r, u;
    scanf("%d %d %d %d", &l, &d, &r, &u);
    int cnt1 = 0, cnt2 = 0, cnt3 = 0, cnt4 = 0;
    if (l - 1 >= 1) cnt1 = query(1, l - 1, 1, n);
    if (r + 1 <= n) cnt2 = query(r + 1, n, 1, n);
    if (d - 1 >= 1) cnt3 = query(1, n, 1, d - 1);
    if (u + 1 <= n) cnt4 = query(1, n, u + 1, n);
    int cnt5 = 0, cnt6 = 0, cnt7 = 0, cnt8 = 0;
    if (l - 1 >= 1 && d - 1 >= 1) cnt5 = query(1, l - 1, 1, d - 1);
    if (r + 1 <= n && d - 1 >= 1) cnt6 = query(r + 1, n, 1, d - 1);
    if (l - 1 >= 1 && u + 1 <= n) cnt7 = query(1, l - 1, u + 1, n);
    if (r + 1 <= n && u + 1 <= n) cnt8 = query(r + 1, n, u + 1, n);
    long long res = f(n) - (f(cnt1) + f(cnt2) + f(cnt3) + f(cnt4) - f(cnt5) -
                            f(cnt6) - f(cnt7) - f(cnt8));
    printf("%lld\n", res);
  }
}
