func_code_string: #include <bits/stdc++.h>   using namespace std;   vector<pair<int, int> > marks(200002);   vector<pair<int, int> > marksbyy(200002);   vector<vector<int> > partials(2005, vector<int>(2005));   vector<vector<int> > inpart(2005, vector<int>(2005));   int n;   void fillpart() {     sort(marks.begin() + 1, marks.begin() + n + 1);     sort(marksbyy.begin() + 1, marksbyy.begin() + n + 1);     for (int i = 1; i <= n; i++) {       int j = marks[i].second;       inpart[(i - 1) / 100][(j - 1) / 100]++;     }     partials[0][0] = inpart[0][0];     for (int i = 1; i <= 2000; i++) {       partials[0][i] = partials[0][i - 1] + inpart[0][i];     }     for (int i = 1; i <= 2000; i++) {       partials[i][0] = partials[i - 1][0] + inpart[i][0];     }     for (int i = 1; i <= 2000; i++) {       for (int j = 1; j <= 2000; j++) {         partials[i][j] = partials[i - 1][j] + partials[i][j - 1] -                          partials[i - 1][j - 1] + inpart[i][j];       }     }   }   int query(int x, int y) {     int ans = 0;     int biggestpartx = x / 100 - 1;     int biggestparty = y / 100 - 1;     if (biggestpartx >= 0 && biggestparty >= 0) {       ans += partials[biggestpartx][biggestparty];       for (int i = (biggestpartx + 1) * 100 + 1; i <= x; i++) {         if (marks[i].second <= (biggestparty + 1) * 100) {           ans++;         }       }       for (int i = (biggestparty + 1) * 100 + 1; i <= y; i++) {         if (marksbyy[i].second <= x) {           ans++;         }       }     } else {       for (int i = 1; i <= x; i++) {         if (marks[i].second <= y) {           ans++;         }       }     }     return ans;   }   int main() {     ios::sync_with_stdio(false);     cin.tie(NULL);     int q;     cin >> n >> q;     vector<int> arr(n);     for (int i = 1; i <= n; i++) {       int x;       cin >> x;       x = n + 1 - x;       marks[i] = make_pair(x, i);       marksbyy[i] = make_pair(i, x);     }     fillpart();     for (int i = 0; i < q; i++) {       int l, d, r, u;       cin >> l >> d >> r >> u;       u = n + 1 - u;       d = n + 1 - d;       long long int topleft = query(u - 1, l - 1);       long long int top = query(u - 1, r) - topleft;       long long int left = query(d, l - 1) - topleft;       long long int inside = query(d, r) - topleft - top - left;       long long int topright = query(u - 1, n) - top - topleft;       long long int bottomleft = query(n, l - 1) - left - topleft;       long long int bottom =           query(n, r) - inside - bottomleft - topleft - top - left;       long long int right =           query(d, n) - inside - topright - topleft - top - left;       long long int bottomright = query(n, n) - inside - topright - topleft -                                   top - left - bottom - bottomleft - right;       long long int ans = 0;       ans += topleft * (bottom + right + bottomright + inside);       ans += topright * (bottom + left + bottomleft + inside);       ans += bottomleft * (top + right + topright + inside);       ans += bottomright * (top + left + topleft + inside);       ans += inside * (topright + topleft + bottomleft + bottomright + top +                        right + bottom + left + inside - 1);       ans += top * (bottom + left + right + bottomleft + bottomright + inside);       ans += right * (top + left + bottom + topleft + bottomleft + inside);       ans += bottom * (top + left + right + topleft + topright + inside);       ans += left * (top + bottom + right + topright + bottomright + inside);       ans /= 2;       cout << ans <<   n ;     }     return 0;   }   