Super OJ 序列计数
题意: 给出序列 a1,a2,……an(0≤ai≤109),求三元组(ai,aj,ak)(1≤i<j<k≤n)满足 ai<aj>ak 的数量。 分析: 开两个 \(BIT\) ,分别维护前面比它小的和后面比它大的,然后组合计数一下即可 代码: #include<bits/stdc++.h> #define lowbit(x) (x & (-x)) #define ll long long #define N (100000 + 5) using namespace std; inline int read() { int cnt = 0, f = 1; char c = getchar(); while (!isdigit(c)) {if (c == '-') f = -f; c = getchar();} while (isdigit(c)) {cnt = (cnt << 3) + (cnt << 1) + c - '0'; c = getchar();} return cnt * f; } int n, q, a[N], b[N << 1]; ll ans; void pre() { sort(b + 1, b + n + 1); q = unique(b + 1, b + n + 1) - b - 1; for (register int i = 1; i <= n; ++i