Submission #151499

# Submission time Handle Problem Language Result Execution time Memory
151499 2019-09-03T12:16:16 Z outsider Arranging Shoes (IOI19_shoes) C++14
0 / 100
888 ms 1048580 KB
#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 pos,ll new_value)
{
	if (tl==tr)
	t[v]=new_value;
    else
	{
	
		ll tm=(tl+tr)/2;
	    if (pos<=tm)
		update(v*2,tl,tm,pos,new_value);
		else
		update(v*2+1,tm+1,tr,pos,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));
}


long long count_swaps(vector<int> s)
{
n=s.size();
a.resize(n+1,1);
t.resize(2*n+1);
build(1,1,n);
map<ll,deque<ll> >mp;
for (int i=0;i<n;i++)
    mp[s[i]].push_back(i);
long long ans=0;
 for (ll i=0;i<n;i++)
 {
    if (a[i]==0)
        continue;
  ll p=mp[-s[i]].front();
  mp[-s[i]].pop_front();
  mp[s[i]].pop_front();
  update(1,1,n,p,0);
  update(1,1,n,i,0);
  a[i]=a[p]=0;
  ans+=get_sum(1,1,n,i,p);
 if (s[i]>0)ans++;
 }
return ans;
}
# Verdict Execution time Memory Grader output
1 Runtime error 882 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 882 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 882 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 888 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 882 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 882 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -