이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |