Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
128189 | 陈志轩 | 车厢重组 | C++ | 通过 | 100 | 2 MS | 1044 KB | 929 | 2024-01-25 14:23:51 |
#include<bits/stdc++.h> #define int long long using namespace std; int n,ans,a[514514],c[514514]; inline int fr(){ register int x = 0,f = 1; static char c = getchar(); while (c < '0' || c > '9'){ if (c == '-'){ f = -1; } c = getchar(); } while (c >= '0' && c <= '9'){ x = (x << 1) + (x << 3) + (c ^ 48); c = getchar(); } return x * f; } inline void fw(int x){ if (x < 0){ putchar('-'); x = -x; } if (x > 9){ fw(x / 10); } putchar(x % 10 + 48); } int lowbit(int x){ return (x & (-x)); } void add(int x,int val){ while (x <= n){ c[x] += val; x += lowbit(x); } } int sum(int x){ int ret = 0; while (x >= 1){ ret += c[x]; x -= lowbit(x); } return ret; } signed main(){ n = fr(); for (int i = 1;i <= n;i++){ a[i] = fr(); } for (int i = 1;i <= n;i++){ add(a[i],1); ans += i - sum(a[i]); } fw(ans); return 0; }