# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
197352 | hank55663 | Arranging Shoes (IOI19_shoes) | C++14 | 387 ms | 148856 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;
int S[200005];
void add(int x,int k){
for(int i =x;i<200005;i+=i&-i){
S[i]+=k;
}
}
int query(int x){
int res=0;
for(int i=x;i>0;i-=i&-i){
res+=S[i];
}
return res;
}
queue<int> pool[200005];
long long count_swaps(std::vector<int> sh) {
//printf("?\n");
set<int> s;
queue<int> *m=pool+100002;
for(int i = 0;i<sh.size();i++){
add(i+1,1);
s.insert(i);
m[sh[i]].push(i);
}
//printf("?\n");
long long ans=0;
while(!s.empty()){
int x=*s.begin();
s.erase(s.begin());
m[sh[x]].pop();
add(x+1,-1);
int y=m[-sh[x]].front();
m[-sh[x]].pop();
s.erase(y);
ans+=query(y);
add(y+1,-1);
//printf("%d %d\n",x,y);
if(sh[x]>0)ans++;
}
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... |