Submission #56782

#TimeUsernameProblemLanguageResultExecution timeMemory
56782hamzqq9Robots (IOI13_robots)C++14
0 / 100
685 ms66560 KiB
#include "robots.h"
 
#include<bits/stdc++.h>
using namespace std;
 
#define ii pair<int,int>
#define st first
#define nd second
#define orta ((bas+son)/2)
 
#define MAX1 1000005
#define MAX2 50005
 
int A,B,T;
int X[MAX2],Y[MAX2];
ii S[2][MAX2*4],toy[MAX1];
 
void build(int node,int bas,int son,int w) {
 
	if(bas==son) {
 
		S[w][node]={0,bas};
 
		return ;
 
	}
 
	build(node*2,bas,orta,w);
	build(node*2+1,orta+1,son,w);
 
	S[w][node]=min(S[w][node*2],S[w][node*2+1]);
 
}
 
priority_queue<int> H;

void zero() {

	while(!H.empty()) H.pop();
 
	build(1,0,A-1,0);
	build(1,0,B-1,1);
 
}
 
void up(int node,int bas,int son,int x,int w) {

	if(bas>x || son<x) return ;
 
	if(bas==x && son==x) {
 
		S[w][node].st++;
 
		return ;
 
	}
 
	up(node*2,bas,orta,x,w);
	up(node*2+1,orta+1,son,x,w);
 
	S[w][node]=min(S[w][node*2],S[w][node*2+1]);
 
}

ii get(int node,int bas,int son,int x,int y,int DAYS,int w) {

	if(bas>=x && son<=y) {
 
		if(bas==son) return S[w][node];
		
		if(S[w][node*2].st<DAYS) return get(node*2,bas,orta,x,y,DAYS,w);
		
		return get(node*2+1,orta+1,son,x,y,DAYS,w);
 
	}
 
	if(orta>=x) {
 
		if(orta+1<=y) {
 
			ii L=get(node*2,bas,orta,x,y,DAYS,w);
 
			if(L.st<DAYS) return L;
 
			return get(node*2+1,orta+1,son,x,y,DAYS,w);
 
		}
 
		return get(node*2,bas,orta,x,y,DAYS,w);
 
	}
 
	return get(node*2+1,orta+1,son,x,y,DAYS,w);
 
}
 
bool check(int DAYS) {
 
	zero();
 
	int last=A;
 
	for(int i=0;i<T;i++) {
 
		while(last-1>=0 && X[last-1]>=toy[i].st) last--; 
 
		ii RASA=(last<A?get(1,0,A-1,last,A-1,DAYS,0):make_pair(DAYS,0));
 
		H.push(-toy[i].nd);
 
		if(last==A || RASA.st==DAYS) {
 
			int valB=-H.top();
 
			H.pop();
 
			int pos=lower_bound(Y,Y+B,valB)-Y;
 
			ii RASB=(pos<B?get(1,0,B-1,pos,B-1,DAYS,1):make_pair(DAYS,0));
 
			if(pos==B || RASB.st==DAYS) {

				return false;
 
			}
			else {
 
				up(1,0,B-1,RASB.nd,1);
 
			}
 
		}
		else {
 
			up(1,0,A-1,RASA.nd,0);
 
		}
 
	}
 
	return true;
 
}
 
int putaway(int A, int B, int T, int X[], int Y[], int W[], int S[]) {
 
	::A=A;
	::B=B;
	::T=T;
 
	for(int i=0;i<A;i++) {
 
		X[i]--;
		::X[i]=X[i];
 
	}
 
	for(int i=0;i<B;i++) {
 
		Y[i]--;
		::Y[i]=Y[i];
 
	}
 
	for(int i=0;i<T;i++) {
 
		toy[i]={W[i],S[i]};
 
	}
 
	sort(::X,::X+A);
	sort(::Y,::Y+B);
 
	sort(toy,toy+T,greater<ii>());

	int bas=1,son=T;
 
	while(bas<=son) {
 
		if(check(orta)) son=orta-1;
		else bas=orta+1;

		if(bas==1 || son==T) return 0;
 
	}
 
	if(bas==T+1) {
 
		return -1;
 
	}
 
	return bas;
 
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...