0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-16 19:45:24 +00:00

351B - Jeff and Furik

https://codeforces.com/problemset/submission/351/173713009
This commit is contained in:
Baoshuo Ren 2022-09-27 21:58:09 +08:00
parent 6d2b982d60
commit fc18c9b0b0
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

43
Codeforces/351/B/B.cpp Normal file
View File

@ -0,0 +1,43 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 3005;
int n, p[N], c[N], ans;
int lowbit(int x) {
return x & -x;
}
void add(int x, int y) {
for (; x <= n; x += lowbit(x)) c[x] += y;
}
int sum(int x) {
int res = 0;
for (; x; x -= lowbit(x)) res += c[x];
return res;
}
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> p[i];
}
for (int i = n; i; i--) {
ans += sum(p[i] - 1);
add(p[i], 1);
}
cout << (ans * 2 - ans % 2) << endl;
return 0;
}