# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
476880 | JovanB | Arranging Shoes (IOI19_shoes) | C++17 | 156 ms | 139344 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;
using ll = long long;
using ld = long double;
const int N = 200000;
int bit[N+5];
void bit_add(int x){
while(x <= N){
bit[x]++;
x += x & -x;
}
}
int bit_get(int x){
int res = 0;
while(x){
res += bit[x];
x -= x & -x;
}
return res;
}
deque <int> ima[N+5];
int tren[N+5];
long long count_swaps(std::vector<int> vec) {
ll res = 0;
int tr = 0;
for(int i=1; i<=N; i++) tren[i] = -1;
for(int i=0; i<vec.size(); i++){
int x = vec[i];
bool left = 0;
if(x < 0) left = 1, x = -x;
if(ima[x].size() && tren[x] != left){
int g = ima[x].front();
ima[x].pop_front();
res += bit_get(N) - bit_get(g);
bit_add(g);
res += left;
}
else{
ima[x].push_back(++tr);
tren[x] = left;
bit_add(tr);
}
}
return res;
}
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... |