# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
268130 | shinjan | Arranging Shoes (IOI19_shoes) | C++14 | 204 ms | 138744 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 <iostream>
#include <bits/stdc++.h>
#include "shoes.h"
#define maxN 200005
using namespace std;
int fen[maxN];
void add(int ind,int n)
{
for(int i=ind;i<=n;i+=(i&(-i)))
{
fen[i]++;
}
}
void brisi(int ind,int n)
{
for(int i=ind;i<=n;i+=(i&(-i)))
{
fen[i]--;
}
}
long long sum(int ind)
{
long long ans=0;
for(int i=ind;i>=1;i-=(i&(-i)))
{
ans+=fen[i];
}
return ans;
}
long long count_swaps(vector <int> s)
{
int n=s.size();
long long ans=0;
queue<int> neg[n/2+1];
queue<int> poz[n/2+1];
for(int i=0;i<s.size();i++)
{
if(s[i]>0)
{
if(neg[s[i]].size()!=0)
{
int pos=neg[s[i]].front();
ans-=(sum(i)-sum(pos+1));
brisi(pos+1,n);
ans+=(i-pos-1);
neg[s[i]].pop();
}
else{
poz[s[i]].push(i);
add(i+1,n);
}
}
if(s[i]<0)
{
int x=abs(s[i]);
if(poz[x].size()!=0)
{
int pos=poz[x].front();
ans-=(sum(i)-sum(pos+1));
brisi(pos+1,n);
ans+=(i-pos);
poz[x].pop();
}
else{
neg[x].push(i);
add(i+1,n);
}
}
}
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... |