This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
ll count_swaps(vector<int> S) {
ll n = S.size(), ans = 0;
tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update> T;
unordered_map<int, deque<int>> M; M.reserve(n);
for(int i = 0; i < n; i++) M[S[i]].push_back(i);
for(int i = 0; i < n; i++) T.insert({i,S[i]});
for(int i = 0; i < n/2; i++) {
auto itr = T.find_by_order(0);
int val = -(*itr).second;
ans += (ll)T.order_of_key({M[val].front(), val});
if(val > 0) ans -= 1LL;
T.erase(itr);
T.erase(T.find({M[val].front(), val}));
M[val].pop_front();
M[-val].pop_front();
}
return ans;
}
/*
int main() {
int t;
vector<int> Q;
while(cin>>t) Q.push_back(t);
cout << count_swaps(Q);
}
*/
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |