Submission #152978

#TimeUsernameProblemLanguageResultExecution timeMemory
152978qkxwsmLast supper (IOI12_supper)C++14
100 / 100
185 ms9632 KiB
#include "advisor.h"
#include <bits/stdc++.h>

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
	if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
	if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) ((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define MAXN 1000013

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

int pos[MAXN];
int rt[MAXN];
bitset<MAXN> important;
set<pii> stor;

void ComputeAdvice(int *C, int N, int K, int M)
{
	//some guys you get are "useless", some guys are not
	//decide which ones are important and which arent.
	FOR(i, 0, N) pos[i] = N;
	FORD(i, N, 0)
	{
		int x = C[i];
		rt[i] = pos[x];
		pos[x] = i;
	}
	FOR(i, 0, K)
	{
		stor.insert({pos[i] + K, i});
		// cerr << "INSERT " << pos[i] + K << ',' << i << endl;
		pos[i] = i;
	}
	FOR(i, 0, N)
	{
		int x = C[i];
		if (stor.find({i + K, x}) != stor.end())
		{
			important[pos[x]] = true;
			stor.erase({i + K, x});
		}
		else
		{
			stor.erase(prev(stor.end()));
		}
		pos[x] = i + K;
		// cerr << "POS " << x << " = " << i + K << endl;
		stor.insert({rt[i] + K, x});
	}
	FOR(i, 0, N + K)
	{
		// cerr << important[i] << ' ';
		WriteAdvice((important[i] ? 1 : 0));
	}
	// cerr << endl;
}
#include "assistant.h"
#include <bits/stdc++.h>

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
	if (a > b) a = b;
}
template<class T, class U>
void ckmax(T &a, U b)
{
	if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define SZ(x) ((int) ((x).size()))
#define ALL(x) (x).begin(), (x).end()
#define MAXN 1000013

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

set<int> useful, useless;

void Assist(unsigned char *A, int N, int K, int R)
{
	FOR(i, 0, K)
	{
		if (A[i])
		{
			useful.insert(i);
		}
		else
		{
			useless.insert(i);
		}
	}
	FOR(i, K, K + N)
	{
		int cur = GetRequest();
		if (useful.find(cur) == useful.end())
		{
			int x = *useless.begin();
			useless.erase(useless.begin());
			PutBack(x);
		}
		else
		{
			useful.erase(cur);
		}
		if (A[i])
		{
			useful.insert(cur);
		}
		else
		{
			useless.insert(cur);
		}
	}
}
#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...