Question link: Click the open link
Evaluate the logarithm of I <j <K & A [I]> A [J]> A [k]
If there are only 2 tuples, the reverse order is used.
A tree array X is used to represent the number before the number I.
Then, sum the array y, and store the number of> A [I] in array X to array y.
# Include <algorithm> # include <cctype> # include <cassert> # include <cstdio> # include <cstring> # include <climits> # include <vector> # include <iostream> using namespace STD; # define ll long longinline void RD (Int & RET) {char C; do {c = getchar ();} while (C <'0' | C> '9'); ret = C-'0'; while (C = getchar ()> = '0' & C <= '9') ret = RET * 10 + (c-'0 ');} # define n 1000005 # define EPS 1e-8 # define INF limit 00ll N; struct node {ll C [N]; inline ll lowbit (ll x) {return X &-X ;} void Init () {memset (C, 0, sizeof C);} ll sum (ll x) {ll ans = 0; while (x <= N + 10) ans + = C [X], x + = lowbit (x); Return ans;} void change (ll x, ll y) {While (X) c [x] + = Y, X-= lowbit (x) ;}} X, Y; int haifei [1000000], panting [1000000]; int main () {ll I, j; while (CIN> N) {ll ans = 0; for (I = 0; I <n; I ++) rd (haifei [I]), panting [I] = haifei [I]; X. init (); Y. init (); sort (haifei, haifei + n); for (I = 0; I <n; I ++) {LL B = (lower_bound (haifei, haifei + N, panting [I])-haifei) + 1; ll siz = y. sum (B); ans + = siz; Y. change (B, X. sum (B); X. change (B, 1) ;}cout <ans <Endl;} return 0 ;}