This documentation is automatically generated by online-judge-tools/verification-helper
This project is maintained by tsutaj
// BIT 略 // Verified: ALDS1_5_D (反転数) signed main() { int n; cin >> n; BIT<int> b(n); vector<int> a(n); map<int, int> m; rep(i,0,n) { cin >> a[i]; m[a[i]]; } int newnum = 1; for(auto &x : m) x.second = newnum++; rep(i,0,n) a[i] = m[a[i]]; int ans = 0; rep(j,0,n) { ans += j - b.sum(a[j]); b.add(a[j], 1); } cout << ans << endl; return 0; }
#line 1 "structure/old/strc_007_bit_recursion.cpp" // BIT 略 // Verified: ALDS1_5_D (反転数) signed main() { int n; cin >> n; BIT<int> b(n); vector<int> a(n); map<int, int> m; rep(i,0,n) { cin >> a[i]; m[a[i]]; } int newnum = 1; for(auto &x : m) x.second = newnum++; rep(i,0,n) a[i] = m[a[i]]; int ans = 0; rep(j,0,n) { ans += j - b.sum(a[j]); b.add(a[j], 1); } cout << ans << endl; return 0; }