# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
289860 | Bill_00 | Arranging Shoes (IOI19_shoes) | C++14 | 206 ms | 269688 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;
queue<int> l[200005], r[200005];
long long s[200005];
int a[200005];
int n;
long long tree[1000005];
void add(int i, int x)
{
while(i <= 2 * n)
{
s[i] += x;
i += i & (-i);
}
}
long long sum(int i)
{
long long res = 0;
while(i > 0)
{
res += s[i];
i -= i & (-i);
}
return res;
}
long long count_swaps(vector<int> b) {
int n=b.size();
n=n/2;
for(int i=0;i<b.size();i++){
a[i+1]=b[i];
}
int i, j;
long long ans = 0;
for(i = 1; i <= 2 * n; i++)
{
if(a[i] > 0) r[a[i]].push(i);
else l[-a[i]].push(i);
}
for(i = 1; i <= 2 * n; i++) add(i, 1);
for(i = 1; i <= 2 * n; i++) if(sum(i) - sum(i - 1) > 0){
if(a[i] < 0)
{
int id;
id = r[-a[i]].front();
ans += sum(id) - sum(i) - 1;
add(id, -1);
l[-a[i]].pop();
r[-a[i]].pop();
}
else {
int id;
id = l[a[i]].front();
ans += sum(id) - sum(i);
add(id, -1);
l[a[i]].pop();
r[a[i]].pop();
}
}
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... |