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 "shoes.h"
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> using o_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T, typename R> using o_map = tree<T, R, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long count_swaps(std::vector<int> s) {
long long n=s.size()/2;
vector<long long> dst;
map<long long,long long> mp;
queue<long long> Q[2*n+2];
for(auto u:s){
if(mp[u]==0){
dst.push_back(min(u,-u));
dst.push_back(max(-u,u));
mp[-u]=1;
}
else{
mp[u]=0;
}
}
for(long long i=0;i<dst.size();i++){
Q[dst[i]+n].push(i+1);
}
vector<long long> inv;
for(auto u:s){
inv.push_back(Q[u+n].front());
Q[u+n].pop();
}
long long cnt=0,ii=0;
o_set<pair<long long,int>> st;
for(auto u:inv){
cnt+=st.order_of_key({-u,0});
st.insert({-u,++ii});
}
return cnt;
}
// signed main() {
// int n;
// assert(1 == scanf("%d", &n));
// vector<int> S(2 * n);
// for (int i = 0; i < 2 * n; i++)
// assert(1 == scanf("%d", &S[i]));
// long long result = count_swaps(S);
// printf("%lld\n", result);
// return 0;
// }
Compilation message (stderr)
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:27:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for(long long i=0;i<dst.size();i++){
| ~^~~~~~~~~~~
# | 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... |