# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
146016 | gs18115 | Arranging Shoes (IOI19_shoes) | C++14 | 150 ms | 71288 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<queue>
#include<algorithm>
#define eb emplace_back
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int>pi;
typedef pair<ll,ll>pl;
const ll inf=1e18;
struct fenwick
{
ll dat[200010];
inline void FI(int x,int p)
{
for(x++;x<200010;x+=x&-x)
dat[x]+=p;
return;
}
inline ll FS(int x)
{
ll ans=0;
for(x++;x>0;x=x&x-1)
ans+=dat[x];
return ans;
}
}FT;
queue<int>v[100010];
long long count_swaps(vector<int>s)
{
ll ans=0;
int n=s.size()/2;
int i;
for(i=0;i<n*2;i++)
{
FT.FI(i,1);
if(s[i]>0)
v[s[i]].push(i);
}
for(i=0;i<n*2;i++)
{
if(s[i]<0)
{
int t=v[-s[i]].front();
v[-s[i]].pop();
FT.FI(i,-1);
FT.FI(t,-1);
if(i<t)
ans+=FT.FS(t)-FT.FS(i);
else
ans+=FT.FS(i)-FT.FS(t)+1;
}
}
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... |