#include<stdio.h> const int MAX_N = 1e5; typedef long long ll; int n; ll bit[2][MAX_N + 1], res; void update(int h, int x, int k) { for (; h; h -= h&-h) bit[k][h] += x; } ll query(int h, int k) { ll s = 0; for (; h <= n; h += h&-h) s += bit[k][h]; return s; } int main() { scanf("%d", &n); for (int i = 0, x; i < n; i++) { scanf("%d", &x); res += query(x + 1, 1); update(x, query(x + 1, 0), 1); update(x, 1, 0); } printf("%lld", res); return 0; }
5012번: 불만 정렬
https://www.acmicpc.net/problem/5012
피드 구독하기:
댓글
(
Atom
)
댓글 없음 :
댓글 쓰기