| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1364605 | takoshanava | Arranging Shoes (IOI19_shoes) | C++20 | 0 ms | 344 KiB |
#include "shoes.h"
#include <bits/stdc++.h>
//#define int long long
#define pb push_back
#define fs first
#define sc second
using namespace std;
const int N = 2e5 + 5;
long long n, bit[N];
void upd(int idx, long long val){
while(idx <= n){
bit[idx] += val;
idx += idx & -idx;
}
}
long long get(int idx){
long long res = 0;
while(idx > 0){
res += bit[idx];
idx -= idx & -idx;
}
return res;
}
long long count_swaps(vector<int> s){
n = s.size();
map<int, deque<int>> lft, rgh;
vector<int> tr(n);
int id = 0;
for(int i = 0; i < n; i++){
int x = s[i];
int sz = abs(x);
if(x > 0){
if(!rgh[sz].empty()){
int j = rgh[sz].front();
rgh[sz].pop_front();
id++;
tr[j] = 2 * id, tr[i] = 2 * id - 1;
}else{
lft[sz].pb(i);
}
}else{
if(!lft[sz].empty()){
int j = lft[sz].front();
lft[sz].pop_front();
id++;
tr[j] = 2 * id - 1, tr[i] = 2 * id;
}else{
rgh[sz].pb(i);
}
}
}
long long ans = 0;
for(int i = 0; i < n; i++){
ans += i - get(tr[i]);
upd(tr[i], 1);
}
return ans;
}
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Result | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
