树状数组裸题
#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #define N 100001 using namespace std; int n, m, ans; int a[N], b[N], R[N], L[N], c[N]; inline int read() { int x = 0, f = 1; char ch = getchar(); for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = -1; for(; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + ch - '0'; return x * f; } inline void add(int x) { for(; x <= m; x += x & -x) c[x]++; } inline int query(int x) { int ret = 0; for(; x; x -= x & -x) ret += c[x]; return ret; } int main() { int i; n = read(); for(i = 1; i <= n; i++) a[i] = b[i] = read(); sort(b + 1, b + n + 1); m = unique(b + 1, b + n + 1) - b - 1; for(i = 1; i <= n; i++) a[i] = lower_bound(b + 1, b + m + 1, a[i]) - b; for(i = 1; i <= n; i++) { add(a[i]); L[i] = i - query(a[i]); } memset(c, 0, sizeof(c)); for(i = n; i >= 1; i--) { add(a[i]); R[i] = (n - i + 1) - query(a[i]); } for(i = 1; i <= n; i++) if(max(L[i], R[i]) > 2 * min(L[i], R[i])) ans++; printf("%d ", ans); return 0; }