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 <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include "shoes.h"
using namespace __gnu_pbds;
using namespace std;
#define ll long long
#define fi first
#define se second
typedef pair<int, int> pii;
#define oset tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update>
long long count_swaps(vector<int> s) {
int n = s.size();
oset st;
map<int, queue<int> > pos;
for(int i = 0; i < n; i++){
pos[s[i]].push(i);
st.insert({i, s[i]});
}
ll res = 0;
while(!st.empty()){
int cur = st.begin()->se;
int pr = pos[-cur].front();
ll ppr = st.order_of_key({pr, -cur}) - int(cur < 0);
res += ppr;
pos[cur].pop();
pos[-cur].pop();
st.erase({pr, -cur});
st.erase(st.begin());
}
return res;
}
# | 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... |