//Knapsack DP is harder than FFT.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define ff first
#define ss second
#define pb emplace_back
#define FOR(i,n) for(int i = 0; i < (n); ++i)
#define FOO(i,a,b) for(int i = (a); i <= (b); ++i)
#define AI(x) (x).begin(),(x).end()
template<typename I> bool chmax(I &a, I b){ return a < b ? (a = b, true) : false;}
template<typename I> bool chmin(I &a, I b){ return a > b ? (a = b, true) : false;}
#ifdef OWO
#define debug(args...) LKJ("[ " + string(#args) + " ]", args)
void LKJ(){ cerr << endl;}
template<typename I, typename...T> void LKJ(I&&x, T&&...t){ cerr<<x<<", ", LKJ(t...);}
template<typename I> void DE(I a, I b){ while(a < b) cerr << *a << " \n"[next(a) == b], ++a;}
#else
#define debug(...) 0
#define DE(...) 0
#endif
#ifdef OWO
void ComputeAdvice(int *C, int N, int K, int M); void WriteAdvice(unsigned char a);
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n, m, k;
cin >> n >> k >> m;
int *c = new int[n];
for(int i = 0; i < n; ++i) cin >> c[i];
ComputeAdvice(c, n, k, m);
return 0;
}
void WriteAdvice(unsigned char a){
putchar(a);
putchar(' ');
}
#else
#include "advisor.h"
#endif
const int maxn = 1e5 + 225;
queue<int> app[maxn];
struct BIT{
int val[maxn];
void modify(int p, int v){
++p;
for(; p <= maxn; p += p & -p) val[p] += v;
}
void insert(int p){ modify(p, 1);}
void erase(int p){ modify(p, -1);}
int query(int p){
++p;
int ans = 0;
for(; p > 0; p -= p & -p) ans += val[p];
return ans;
}
int count(int p){
return query(p) - query(p - 1);
}
int find(int p){
return query(p);
}
};
void ComputeAdvice(int *C, int N, int K, int M){
int L = __lg(N - 1);
for(int i = 0; i < N; ++i) app[C[i]].emplace(i);
for(int i = 0; i < N; ++i) app[i].emplace(8e7);
set<int> scaff;
priority_queue<pii> pq;
for(int i = 0; i < K; ++i) scaff.insert(i);
for(int i = 0; i < K; ++i) pq.emplace(app[i].front(), i);
auto wn = [&L](int a){
for(int i = L; i >= 0; --i){
WriteAdvice((a >> i & 1) + '0');
}
};
for(int i = 0; i < N; ++i){
int c = C[i]; app[c].pop();
if(scaff.count(c) != 0){
wn(c);
continue;
}
int eek;
do{
auto tp = pq.top(); pq.pop();
eek = tp.ss;
} while(scaff.count(eek) == 0);
wn(eek);
scaff.erase(eek);
scaff.insert(c);
pq.emplace(app[c].front(), c);
}
}
//Knapsack DP is harder than FFT.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define ff first
#define ss second
#define pb emplace_back
#define FOR(i,n) for(int i = 0; i < (n); ++i)
#define FOO(i,a,b) for(int i = (a); i <= (b); ++i)
#define AI(x) (x).begin(),(x).end()
template<typename I> bool chmax(I &a, I b){ return a < b ? (a = b, true) : false;}
template<typename I> bool chmin(I &a, I b){ return a > b ? (a = b, true) : false;}
#ifdef OWO
#define debug(args...) LKJ("[ " + string(#args) + " ]", args)
void LKJ(){ cerr << endl;}
template<typename I, typename...T> void LKJ(I&&x, T&&...t){ cerr<<x<<", ", LKJ(t...);}
template<typename I> void DE(I a, I b){ while(a < b) cerr << *a << " \n"[next(a) == b], ++a;}
#else
#define debug(...) 0
#define DE(...) 0
#endif
#ifdef OWO
void Assist(unsigned char *A, int N, int K, int R); void PutBack(int T);
int GetRequest();
int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int n, k, r; cin >> n >> k >> r;
unsigned char * a = new unsigned char[r];
for(int i = 0; i < r; ++i) cin >> a[i];
Assist(a, n, k, r);
return 0;
}
int GetRequest(){
const int a[4] = {2, 0, 3, 0};
static int p = 0;
return a[p++];
}
void PutBack(int T){
cout << T << ' ';
}
#else
#include "assistant.h"
#endif
const int maxn = 1e5 + 225;
struct BIT{
int val[maxn];
void modify(int p, int v){
++p;
for(; p <= maxn; p += p & -p) val[p] += v;
}
void insert(int p){ modify(p, 1);}
void erase(int p){ modify(p, -1);}
int query(int p){
++p;
int ans = 0;
for(; p > 0; p -= p & -p) ans += val[p];
return ans;
}
int count(int p){
return query(p) - query(p - 1);
}
int find(int p){
return query(p);
}
int findk(int k){
++k;
int l = 1, r = maxn - 1, m;
while(l < r){
m = (l + r) / 2;
//debug(l, r, m, query(m));
if(query(m) >= k) r = m - 1;
else l = m + 1;
}
return l;
}
};
void Assist(unsigned char *A, int N, int K, int R){
int L = __lg(N - 1);
auto GC = [&](){
static int p = 0;
return A[p++];
};
set<int> scaff;
for(int i = 0; i < K; ++i) scaff.insert(i);
for(int i = 0; i < N; ++i){
int c = GetRequest();
unsigned char cmd = GC();
int ans = 0;
for(int i = 0; i <= L; ++i){
ans = (ans << 1) | (GC() == '1' ? 1 : 0);
}
//debug(ans);
if(ans == c) continue;
PutBack(ans);
scaff.erase(ans);
scaff.insert(c);
}
}
Compilation message
assistant.cpp: In function 'void Assist(unsigned char*, int, int, int)':
assistant.cpp:89:17: warning: unused variable 'cmd' [-Wunused-variable]
89 | unsigned char cmd = GC();
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
54 ms |
68428 KB |
Error - advice must be 0 or 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
56 ms |
68576 KB |
Error - advice must be 0 or 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
75 ms |
69988 KB |
Error - advice must be 0 or 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
55 ms |
68468 KB |
Error - advice must be 0 or 1 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
85 ms |
70112 KB |
Error - advice must be 0 or 1 |
2 |
Incorrect |
84 ms |
70224 KB |
Error - advice must be 0 or 1 |
3 |
Incorrect |
90 ms |
70116 KB |
Error - advice must be 0 or 1 |
4 |
Incorrect |
82 ms |
70116 KB |
Error - advice must be 0 or 1 |
5 |
Incorrect |
83 ms |
70116 KB |
Error - advice must be 0 or 1 |
6 |
Incorrect |
81 ms |
70116 KB |
Error - advice must be 0 or 1 |
7 |
Incorrect |
82 ms |
70540 KB |
Error - advice must be 0 or 1 |
8 |
Incorrect |
81 ms |
70244 KB |
Error - advice must be 0 or 1 |
9 |
Incorrect |
82 ms |
70244 KB |
Error - advice must be 0 or 1 |
10 |
Incorrect |
97 ms |
70364 KB |
Error - advice must be 0 or 1 |