PAT (Top Level) Practice 1009 Triple Inversions (35)
逆序对问题的升级版本(不知道的童鞋自行百度BIT/线段树求逆序对) 本体思路以三个数中间的数为基准,找前面比他大得数有几个 后面比他小的数有几个(可以算出来) 然后相乘+到res里即可 #include <bits/stdc++.h> using namespace std; #define N (int)1e5+10 int arr[N]; #define lc root<<1 #define rc root<<1|1 typedef long long ll; struct seg{ int l, r; ll he, lazy, tag; }t[4*N]; void build(int root, int l, int r) { t[root].l = l, t[root].r = r; t[root].lazy = 0; t[root].tag = -1; if (l == r) { t[root].he = 0; return; } int m = (l + r) >> 1; build(lc, l, m); build(rc, m+1, r); t[root].he = t[lc].he + t[rc].he; } void imptag(int root, ll change) { t[root].tag = change; t[root].he = (t[root]