# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
776736 | Warinchai | Arranging Shoes (IOI19_shoes) | C++14 | 206 ms | 274800 KiB |
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>
using namespace std;
queue<int>q[200005];
queue<int>nq[200005];
int check[200005];
struct fenwick{
int info[200005];
void upd(int idx,int val){
for(int i=idx;i<=200000;i+=i&-i){
info[i]+=val;
}
}
int fsum(int idx){
int sum=0;
for(int i=idx;i>0;i-=i&-i){
sum+=info[i];
}
return sum;
}
}fw;
long long count_swaps(vector<int>s) {
//cout<<"work"<<endl;
for(int i=0;i<s.size();i++){
if(s[i]>=0){
q[s[i]].push(i+1);
}else{
nq[s[i]*-1].push(i+1);
}
}
long long ans=0;
for(int i=0;i<s.size();i++){
if(check[i]==0){
int x=s[i];
int nx=s[i]*-1;
if(x>=0){
if(nq[x].empty()||q[x].empty()){
cout<<"wtf"<<endl;
return 69;
}
int id=nq[x].front();
nq[x].pop();
q[x].pop();
int sz=id-1-i;
int st=i+1;
//cout<<"id,i:"<<id<<" "<<i+1<<endl;
//cout<<sz<<" ";
sz-=fw.fsum(id)-fw.fsum(st);
//cout<<sz<<endl;
ans+=sz;
if(i<0||id-1<0){
return 69420;
}
check[i]=1;
check[id-1]=1;
fw.upd(id,1);
}else{
if(nq[nx].empty()||q[nx].empty()){
cout<<"wtf"<<endl;
return 69;
}
int id=q[nx].front();
q[nx].pop();
nq[nx].pop();
//cout<<"id,i:"<<id<<" "<<i+1<<endl;
int sz=id-2-i;
int st=i+1;
//cout<<sz<<" ";
sz-=fw.fsum(id)-fw.fsum(st);
ans+=sz;
//cout<<sz<<endl;
if(i<0||id-1<0){
return 69420;
}
check[i]=1;
check[id-1]=1;
fw.upd(id,1);
}
}
}
//cout<<ans<<endl;
return ans;
}
Compilation message (stderr)
# | 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... |