이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#include <bits/stdc++.h>
#include "ext/pb_ds/assoc_container.hpp"
using namespace std;
using namespace __gnu_pbds;
#define sz(x) (int)(x.size())
#define fi first
#define se second
template<typename T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
typedef long long ll;
typedef pair<int,int> ii;
const int MX = (int)(2e5+5);
int n;
vector<int> vec[2*MX];
ll count_swaps(vector<int> s) {
n=sz(s);
ordered_set <ii> X;
ll ans=0;
for (int i = n-1; i >= 0; i--)
{
X.insert({i,s[i]});
if(s[i]>0)vec[s[i]].push_back(i);
else vec[-s[i]+n].push_back(i);
}
while(!X.empty()){
ii f=(*X.begin()),m;
if(f.se<0){
vec[-f.se+n].pop_back();
m={vec[-f.se].back(),-f.se};
vec[-f.se].pop_back();
}
else{
vec[f.se].pop_back();
m={vec[f.se+n].back(),-f.se};
vec[f.se+n].pop_back();
}
ans+=X.order_of_key(m)-1+(f.se>0);
X.erase(X.begin()),X.erase(m);
}
return ans;
}
# | 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... |