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>
#define ll long long
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
using namespace std;
void ComputeAdvice(int *c, int n, int k, int m)
{
vector <ll> cnt(n+k, 0), a(k), p(n);
iota(a.begin(), a.end(), n);
for (ll i=0; i<n; i++) p[i]=i<k?i:-1;
vector <vector <ll>> pos(n);
for (ll i=n-1; i>=0; i--) pos[c[i]].pb(i);
auto get=[&](ll i) {return pos[i].size()?pos[i].back():n+1;};
set <pll> s;
for (ll i=0; i<k; i++)
s.insert({get(i), i});
for (ll i=0; i<n; i++)
{
if (p[c[i]]!=-1)
{
cnt[a[p[c[i]]]]++;
s.erase(s.find({get(c[i]), c[i]}));
pos[c[i]].pop_back();
s.insert({get(c[i]), c[i]});
}
else
{
ll id=(*prev(s.end())).se;
s.erase(prev(s.end()));
pos[c[i]].pop_back();
a[p[id]]=i, p[c[i]]=p[id], p[id]=-1;
s.insert({get(c[i]), c[i]});
}
}
for (ll i=n; i<n+k; i++)
{
for (ll j=0; j<cnt[i]; j++) WriteAdvice(1);
WriteAdvice(0);
}
for (ll i=0; i<n; i++)
{
for (ll j=0; j<cnt[i]; j++) WriteAdvice(1);
WriteAdvice(0);
}
return;
}
#include "assistant.h"
#include<bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
using namespace std;
void Assist(unsigned char *a, int n, int k, int r)
{
ll ptr=0;
vector <ll> ok, cnt(k, 0), p(n, -1);
auto get=[&]()
{
ll ans=0;
while (a[ptr]==1) ans++, ptr++;
ptr++; return ans;
};
for (ll i=0; i<k; i++)
{
cnt[i]=get(), p[i]=i;
if (!cnt[i]) ok.pb(i);
}
for (ll i=0; i<n; i++)
{
ll cr=GetRequest();
if (p[cr]!=-1)
{
cnt[cr]--;
if (!cnt[cr]) ok.pb(cr);
}
else
{
ll id=ok.back(); ok.pop_back();
PutBack(id), p[cr]=id, cnt[cr]=get();
if (!cnt[cr]) ok.pb(cr);
}
}
}
# | 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... |