# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
296607 | zoooma13 | Arranging Shoes (IOI19_shoes) | C++14 | 450 ms | 25976 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 "bits/stdc++.h"
#include "shoes.h"
using namespace std;
vector <int> bit;
void upd(int idx){
for(int i=idx+5; i<bit.size(); i+=(i&-i))
bit[i] += 1;
}
int ask(int idx){
int ret = 0;
for(int i=idx+5; i; i-=(i&-i))
ret += bit[i];
return ret;
}
int qry(int l ,int r){
return r < l? 0 : r-l+1 - ask(r)+ask(l-1);
}
long long count_swaps(vector<int> s) {
bit.resize((int)s.size() + 13);
map <int ,vector<int>> mp;
for(int i=(int)s.size()-1; ~i; i--)
mp[s[i]].push_back(i);
long long ans = 0;
for(int i=0; i<s.size(); i++) if(qry(i ,i)){
int x = s[i]; mp[x].pop_back();
int y_idx = mp[-x].back(); mp[-x].pop_back();
upd(i) ,upd(y_idx);
ans += qry(i+1 ,y_idx-1)+(x > 0);
}
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... |