이 제출은 이전 버전의 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) {
long long ans=1e9;
int n=s.size()>>1;
vector<int>sup;
sup.resize(2*n);
vector<int>perm(n),perm2(n),CR(n);
int CC=0;
iota(perm.begin(),perm.end(),0);
for(int i=0;i<n*2;i++) if(s[i]<0)
otherpos[-s[i]].push(CC++);
for(int i=0;i<n*2;i++) if(s[i]>0) {
int x=otherpos[s[i]].front();
CR[x]=CC;
otherpos[s[i]].pop();
perm2[CC++]=x;
}
for(int i=0;i<n;i++)for(int j=1;j<n-i;j++)
if(perm[j]<perm[j-1]&&CR[j]<CR[j-1]^perm2[CR[j]]<perm2[CR[j-1]])
swap(perm[j],perm[j-1]),swap(perm2[CR[j]],perm2[CR[j-1]]);
CC=0;
for(int i=0;i<n*2;i++)
if(s[i]<0) sup[i]=2*perm[CC],
otherpos[-s[i]].push(2*perm[CC++]+1);
for(int i=0;i<n*2;i++)if(s[i]>0)
sup[i]=otherpos[s[i]].front(),otherpos[s[i]].pop();
return calc(sup);
}
컴파일 시 표준 에러 (stderr) 메시지
shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:34:36: warning: suggest parentheses around comparison in operand of '^' [-Wparentheses]
34 | if(perm[j]<perm[j-1]&&CR[j]<CR[j-1]^perm2[CR[j]]<perm2[CR[j-1]])
shoes.cpp:18:15: warning: unused variable 'ans' [-Wunused-variable]
18 | long long ans=1e9;
| ^~~
# | 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... |