#include "advisor.h"
#include <bits/stdc++.h>
#ifdef local
#define debug(...) qqbx(#__VA_ARGS__, __VA_ARGS__)
template <typename H, typename ...T>
void qqbx(const char *s, const H& h, T &&...args) {
for(; *s && *s != ','; ++s) if(*s != ' ') std::cerr << *s;
std::cerr << " = " << h << (sizeof...(T) ? ", " : "\n");
if constexpr(sizeof...(T)) qqbx(++s, args...);
}
#define safe \
std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#else
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local
using namespace std;
typedef pair<int,int> pii;
void ComputeAdvice(int *C, int n, int k, int m) {
int L = __lg(n-1)+1;
debug(L);
auto W = [&](int x) -> void {
for(int i = 0; i < L; i++) {
WriteAdvice(x & 1);
x >>= 1;
}
};
vector<bool> ok(n);
for(int i = 0; i < k; i++) ok[i] = true;
vector<int> nxt(n), last(n, n);
for(int i = n-1; i >= 0; i--) {
nxt[i] = last[C[i]];
last[C[i]] = i;
}
priority_queue<pii> pq;
for(int i = 0; i < k; i++) pq.push({last[i], i});
for(int i = 0; i < n; i++) {
int r = C[i];
if(!ok[r]) {
int x = pq.top().second; pq.pop();
W(x);
ok[x] = false;
ok[r] = true;
// assert(nxt[i] == n || C[nxt[i]] == r);
// pq.push({nxt[i], r});
int pos = n;
for(int j = i+1; j < n; j++) if(C[j] == r) {
pos = j;
break;
}
pq.push({pos, r});
}
}
}
#include "advisor.h"
#include <bits/stdc++.h>
#ifdef local
#define debug(...) qqbx(#__VA_ARGS__, __VA_ARGS__)
template <typename H, typename ...T>
void qqbx(const char *s, const H& h, T &&...args) {
for(; *s && *s != ','; ++s) if(*s != ' ') std::cerr << *s;
std::cerr << " = " << h << (sizeof...(T) ? ", " : "\n");
if constexpr(sizeof...(T)) qqbx(++s, args...);
}
#define safe \
std::cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#else
#define debug(...) ((void)0)
#define safe ((void)0)
#endif // local
using namespace std;
typedef pair<int,int> pii;
void ComputeAdvice(int *C, int n, int k, int m) {
int L = __lg(n-1)+1;
debug(L);
auto W = [&](int x) -> void {
for(int i = 0; i < L; i++) {
WriteAdvice(x & 1);
x >>= 1;
}
};
vector<bool> ok(n);
for(int i = 0; i < k; i++) ok[i] = true;
vector<int> nxt(n), last(n, n);
for(int i = n-1; i >= 0; i--) {
nxt[i] = last[C[i]];
last[C[i]] = i;
}
priority_queue<pii> pq;
for(int i = 0; i < k; i++) pq.push({last[i], i});
for(int i = 0; i < n; i++) {
int r = C[i];
if(!ok[r]) {
int x = pq.top().second; pq.pop();
W(x);
ok[x] = false;
ok[r] = true;
// assert(nxt[i] == n || C[nxt[i]] == r);
// pq.push({nxt[i], r});
int pos = n;
for(int j = i+1; j < n; j++) if(C[j] == r) {
pos = j;
break;
}
pq.push({pos, r});
}
}
}
Compilation message
/tmp/cc6M1Xz9.o: In function `ComputeAdvice(int*, int, int, int)':
assistant.cpp:(.text+0x28f): undefined reference to `WriteAdvice(unsigned char)'
/tmp/ccIO9NaD.o: In function `main':
assistant_grader.cpp:(.text.startup+0x21f): undefined reference to `Assist(unsigned char*, int, int, int)'
collect2: error: ld returned 1 exit status