Submission #151498

# Submission time Handle Problem Language Result Execution time Memory
151498 2019-09-03T12:13:25 Z outsider Arranging Shoes (IOI19_shoes) C++14
0 / 100
843 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 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));
}


long long count_swaps(vector<int> s)
{
n=s.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[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,p,0);
  update(1,1,n,i,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 843 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 843 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 843 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 842 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 843 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 843 ms 1048580 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -