이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "shoes.h"
#include<bits/extc++.h>
#include<bits/stdc++.h>
using namespace __gnu_pbds;
using namespace std;
queue<int> otherpos[100100];
long long calc(vector<int>v){
long long ans=0;
int K=0;
tree<int,null_type,less<>,rb_tree_tag,tree_order_statistics_node_update>st;
for(auto i:v) {
st.insert(i);
ans+=K++-st.order_of_key(i);
}
return ans;
}
long long count_swaps(std::vector<int> s) {
int n=s.size()>>1,CC=0;
vector<int>sup,sup2;
sup.resize(2*n);
sup2.resize(2*n);
for(int i=0;i<n*2;i++)
if(s[i]<0) sup[i]=2*CC,
otherpos[-s[i]].push(2*CC+++1);
for(int i=0;i<n*2;i++)if(s[i]>0)
sup[i]=otherpos[s[i]].front(),otherpos[s[i]].pop();
CC=0;
for(int i=0;i<n*2;i++)
if(s[i]>0) sup2[i]=2*CC+1,
otherpos[s[i]].push(2*CC++);
for(int i=0;i<n*2;i++)if(s[i]<0)
sup2[i]=otherpos[-s[i]].front(),otherpos[-s[i]].pop();
return min(calc(sup),calc(sup2));
}
# | 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... |