func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 3;   struct tree {     long long sum;     int tag;     int lc;     int rc;   } a[N << 1];   long long s[N];   int n, m, t = 1;   long long ans;   long long win;   vector<pair<long long, long long> > other, change;   inline int read() {     int v = 0, c = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch ==  - ) c = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       v = v * 10 + ch - 48;       ch = getchar();     }     return v * c;   }   inline void pushup(int u) { a[u].sum = a[a[u].lc].sum + a[a[u].rc].sum; }   inline void pushdown(int u, int l, int r) {     if (a[u].tag) {       int mid = (l + r) >> 1;       a[a[u].lc].sum = mid - l + 1 - a[a[u].lc].sum;       a[a[u].lc].tag ^= 1;       a[a[u].rc].sum = r - mid - a[a[u].rc].sum;       a[a[u].rc].tag ^= 1;     }     a[u].tag = 0;   }   void build(int u, int l, int r) {     if (l == r) return;     int mid = (l + r) >> 1;     a[u].lc = ++t;     build(a[u].lc, l, mid);     a[u].rc = ++t;     build(a[u].rc, mid + 1, r);     pushup(u);   }   long long query(int u, int l, int r, int ll, int rr, int w) {     if (l == ll && r == rr) {       if (w == 1) return a[u].sum;       return r - l + 1 - a[u].sum;     }     pushdown(u, l, r);     int mid = (l + r) >> 1;     if (rr <= mid)       return query(a[u].lc, l, mid, ll, rr, w);     else if (ll > mid)       return query(a[u].rc, mid + 1, r, ll, rr, w);     else       return query(a[u].lc, l, mid, ll, mid, w) +              query(a[u].rc, mid + 1, r, mid + 1, rr, w);   }   void updata(int u, int l, int r, int ll, int rr) {     if (l == ll && r == rr) {       a[u].sum = r - l + 1 - a[u].sum;       a[u].tag ^= 1;       return;     }     pushdown(u, l, r);     int mid = (l + r) >> 1;     if (rr <= mid)       updata(a[u].lc, l, mid, ll, rr);     else if (ll > mid)       updata(a[u].rc, mid + 1, r, ll, rr);     else {       updata(a[u].lc, l, mid, ll, mid);       updata(a[u].rc, mid + 1, r, mid + 1, rr);     }     pushup(u);   }   int main() {     n = read(), m = read();     for (int i = 1; i <= n; ++i) s[i] = (long long)read();     sort(s + 1, s + n + 1);     for (int i = 1; i <= m; ++i) {       int l = read(), r = read();       l = lower_bound(s + 1, s + n + 1, l) - s;       r = upper_bound(s + 1, s + n + 1, r) - s - 1;       if (l > r) continue;       change.push_back(make_pair(l, r));       other.push_back(make_pair(r, l));     }     build(1, 1, n);     sort(change.begin(), change.end());     sort(other.begin(), other.end());     ans = (long long)(n - 2) * (n - 1) * n / 6;     for (int i = 1, r = 0, l = 0; i <= n; ++i) {       while (l < change.size() && change[l].first == i) {         updata(1, 1, n, change[l].first, change[l].second);         l++;       }       win = 0;       if (i != 1) win += query(1, 1, n, 1, i - 1, 0);       if (i != n) win += query(1, 1, n, i + 1, n, 1);       ans -= win * (win - 1) / 2;       while (r < other.size() && other[r].first == i) {         updata(1, 1, n, other[r].second, other[r].first);         r++;       }     }     cout << ans << endl;     return 0;   }   