Submission #151443

#TimeUsernameProblemLanguageResultExecution timeMemory
151443outsiderArranging Shoes (IOI19_shoes)C++14
Compilation error
0 ms0 KiB
#include <bits/stdc++.h>
#include "shoes.h"
#define ll int
#define x first
#define y second
using namespace std;
ll n;
vector<ll>a;
vector<ll>t;
void build(ll v,ll tl,ll tr)
{
	if (tl==tr)
	t[v]=a[tl];
    else
    {
       ll tm=(tl+tr)/2;
    	build(v*2,tl,tm);
    	build(v*2+1,tm+1,tr);
    	t[v]=t[2*v]+t[2*v+1];
	}
}
void update(ll v,ll tl,ll tr,ll l,ll r,ll new_value)
{
	if (tl==l && tr==r)
	t[v]=new_value;
    else
	{
		if (l>r)return;
		ll tm=(tl+tr)/2;
		update(v*2,tl,tm,l,min(tm,r),new_value);
		update(v*2+1,tm+1,tr,max(tm+1,l),r,new_value);
	 t[v]=t[2*v]+t[2*v+1];
	}

}

ll get_sum(ll v,ll tl,ll tr,ll l,ll r)
{
	if (l>r)return 0;
	if (tl==l && tr==r)
	return t[v];

	ll tm=(tl+tr)/2;
	return min(get_sum(v*2,tl,tm,l,min(tm,r)),
	get_sum(v*2+1,tm+1,tr,max(l,tm+1),r));
}


ll count_swaps(vector<ll> d)
{
n=d.size();
a.resize(n+1,1);
t.resize(4*n+1);
build(1,1,n);
map<ll,deque<ll> >mp;
for (int i=0;i<n;i++)
    mp[d[i]].push_back(i);
ll ans=0;
 for (ll i=0;i<n;i++)
 {
    if (a[i]==0)
        continue;
  ll p=mp[-d[i]].front();
  mp[-d[i]].pop_front();
  mp[d[i]].pop_front();
  update(1,1,n,p,p,0);
  update(1,1,n,i,i,0);
  a[i]=a[p]=0;
  ans+=get_sum(1,1,n,i,p);
 if (d[i]>0)ans++;
 }

return ans;
}

Compilation message (stderr)

shoes.cpp: In function 'int count_swaps(std::vector<int>)':
shoes.cpp:49:4: error: ambiguating new declaration of 'int count_swaps(std::vector<int>)'
 ll count_swaps(vector<ll> d)
    ^~~~~~~~~~~
In file included from shoes.cpp:2:0:
shoes.h:7:11: note: old declaration 'long long int count_swaps(std::vector<int>)'
 long long count_swaps(std::vector<int> S);
           ^~~~~~~~~~~