func_code_string: #include <bits/stdc++.h>   using namespace std;   template <class T1, class T2>   ostream& operator<<(ostream& os, const pair<T1, T2>& v) {     os <<  (  << v.first <<     << v.second <<  ) ;     return os;   }   template <typename T, typename U = typename T::value_type,             typename = typename enable_if<!is_same<T, string>::value>::type>   ostream& operator<<(ostream& os, const T& v) {     os <<  [ ;     for (const auto& it : v) os << it <<    ;     if (!v.empty()) os <<   b ;     os <<  ] ;     return os;   }   int64_t binom2(int64_t N) {     if (N < 2) return 0;     return (N * (N - 1)) / 2;   }   struct Counter {     struct Node {       vector<int> y;       unique_ptr<Node> left, right;       Node(const vector<int>& p, int node_left, int node_right)           : y(p.begin() + node_left, p.begin() + node_right) {         sort((y).begin(), (y).end());         if (y.size() >= 2) {           int node_middle = (node_left + node_right) / 2;           left.reset(new Node(p, node_left, node_middle));           right.reset(new Node(p, node_middle, node_right));         }       }     };     unique_ptr<Node> root;     void init(const vector<int>& p) { root.reset(new Node(p, 0, p.size())); }     int go_count(const Node* node, int node_left, int node_right, int l, int r,                  int d, int u) {       if (node_left >= r || node_right <= l) return 0;       if (l <= node_left && node_right <= r)         return upper_bound((node->y).begin(), (node->y).end(), u) -                lower_bound((node->y).begin(), (node->y).end(), d);       int node_middle = (node_left + node_right) / 2;       return go_count(node->left.get(), node_left, node_middle, l, r, d, u) +              go_count(node->right.get(), node_middle, node_right, l, r, d, u);     }     int count(int l, int r, int d, int u) {       return go_count(root.get(), 0, root->y.size(), l, r + 1, d, u);     }   };   int N, Q;   int main() {     cin.tie(0);     cout.tie(0);     ios_base::sync_with_stdio(0);     cin >> N >> Q;     vector<int> p(N);     for (int i = 0; i < (N); i++) {       cin >> p[i];       p[i]--;     }     Counter counter;     counter.init(p);     for (int i = 0; i < (Q); i++) {       int l, d, r, u;       cin >> l >> d >> r >> u;       l--, d--, r--, u--;       int64_t ans = binom2(N) - binom2(l) - binom2(N - r - 1);       ans -= binom2(counter.count(0, N - 1, u + 1, N - 1));       ans -= binom2(counter.count(0, N - 1, 0, d - 1));       ans += binom2(counter.count(0, l - 1, 0, d - 1));       ans += binom2(counter.count(0, l - 1, u + 1, N - 1));       ans += binom2(counter.count(r + 1, N - 1, 0, d - 1));       ans += binom2(counter.count(r + 1, N - 1, u + 1, N - 1));       cout << ans <<   n ;     }     return 0;   }   