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 "advisor.h"
#include<bits/stdc++.h>
using namespace std;
#define MAX 100005
#define INF 1e9
struct nodo
{
int v, p;
bool operator < ( const nodo & a ) const
{
if( a.p != p )
return a.p > p;
return a.v < v;
}
};
bool activo[MAX];
int aparicion[MAX];
int sig[MAX];
int posde[MAX];
int maxbits;
priority_queue < nodo > q;
void empuja( int x )
{
for( int i = maxbits - 1; i >= 0; i -- )
{
if( x & ( 1 << i ) )
WriteAdvice( 1 );
else
WriteAdvice( 0 );
}
}
void ComputeAdvice(int *C, int N, int K, int M) {
maxbits = ( int ) ceil( log2( K ) );
for( int i = 0; i < N; i ++ )
{
aparicion[i] = INF;
posde[i] = INF;
}
for( int i = N-1; i >= 0; i -- )
{
int val = C[i];
sig[i] = aparicion[val];
aparicion[val] = i;
}
for( int i = 0; i < K; i ++ )
{
posde[i] = i;
activo[i] = true;
q.push( { i , aparicion[i] } );
}
for( int i = 0; i < N; i ++ )
{
int val = C[i];
if( activo[val] )
{
empuja( posde[val] );
q.push( { val , sig[i] } );
}
else
{
while( q.top().p < i )
q.pop();
nodo act = q.top();
activo[act.v] = false;
posde[val] = posde[act.v];
posde[act.v] = INF;
q.pop();
empuja( posde[val] );
q.push( { val , sig[i] } );
activo[val] = true;
}
}
}
#include "assistant.h"
#include<bits/stdc++.h>
using namespace std;
#define MAX 100005
#define INF 1e9
int posi[MAX];
int estado[MAX];
void Assist(unsigned char *A, int N, int K, int R) {
int numbits = ( int ) ceil( log2( K ) );
int idx = numbits - 1;
for( int i = 0; i < N; i ++ )
posi[i] = INF;
for( int i = 0; i < K; i ++ )
{
posi[i] = i;
estado[i] = i;
}
for( int i = 0; i < N; i ++ )
{
int color = GetRequest( );
int quita = 0;
for( int j = 0; j < numbits; j ++ )
if( A[idx - j] == 1 )
quita += ( 1 << j );
if( posi[color] != quita )
{
PutBack( estado[quita] );
posi[estado[quita]] = INF;
posi[color] = quita;
estado[quita] = color;
}
idx += numbits;
}
}
# | 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... |