# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
259194 | algorithm16 | Arranging Shoes (IOI19_shoes) | C++14 | 393 ms | 28328 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<iostream>
#include<map>
#include<vector>
using namespace std;
typedef long long int llint;
llint fwt[200005],bio[200005];
vector <int> v;
void update(int x,int v) {
for(x;x<200005;x+=x&-x) fwt[x]+=v;
}
llint query(int x) {
llint ret=0;
for(x;x>0;x-=x&-x) ret+=fwt[x];
return ret;
}
map <int,vector <int> > m;
long long count_swaps(std::vector<int> s) {
llint ret=0;
for(int i=s.size()-1;i>=0;i--) {
m[s[i]].push_back(i);
update(i+1,1);
}
for(int i=0;i<s.size();i++) {
if(bio[i]) continue;
int ind=m[-s[i]].back();
m[-s[i]].pop_back();
m[s[i]].pop_back();
ret+=query(ind)-query(i)-1+(s[i]>0);
bio[ind]=1;
update(ind+1,-1);
update(i+1,-1);
//cout << ret << "\n";
}
return ret;
}
/*int main()
{
int n;
cin >> n;
for(int i=0;i<n;i++) {
int x;
cin >> x;
v.push_back(x);
}
cout << count_swaps(v);
return 0;
}*/
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... |