#include <bits/stdc++.h>
#include "advisor.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
#define pb push_back
#define f first
#define s second
namespace debug {
const int DEBUG = true;
template<class T1, class T2>
void pr(const pair<T1, T2> &x);
template<class T, size_t SZ>
void pr(const array<T, SZ> &x);
template<class T>
void pr(const vector<T> &x);
template<class T>
void pr(const set<T> &x);
template<class T1, class T2>
void pr(const map<T1, T2> &x);
template<class T>
void pr(const T &x) { if (DEBUG) cout << x; }
template<class T, class... Ts>
void pr(const T &first, const Ts &... rest) { pr(first), pr(rest...); }
template<class T1, class T2>
void pr(const pair<T1, T2> &x) { pr("{", x.f, ", ", x.s, "}"); }
template<class T>
void prIn(const T &x) {
pr("{");
bool fst = 1;
for (auto &a : x) {
pr(fst ? "" : ", ", a), fst = 0;
}
pr("}");
}
template<class T, size_t SZ>
void pr(const array<T, SZ> &x) { prIn(x); }
template<class T>
void pr(const vector<T> &x) { prIn(x); }
template<class T>
void pr(const set<T> &x) { prIn(x); }
template<class T1, class T2>
void pr(const map<T1, T2> &x) { prIn(x); }
void ps() { pr("\n"), cout << flush; }
template<class Arg, class... Args>
void ps(const Arg &first, const Args &... rest) {
pr(first, " ");
ps(rest...);
}
}
using namespace debug;
const int MAXN = 1e5;
queue<int> nUse[MAXN];
void ComputeAdvice(int *C, int N, int K, int M) {
vi used(2 * N, 0);
vi tInsert(N, 0);
vi contain(N, 0);
for (int i = 0; i < N; i++) {
nUse[C[i]].push(i);
}
for (int cC = 0; cC < N; cC++) {
nUse[cC].push(N);
}
set<pi> allNext;
for (int cC = 0; cC < K; cC++) {
allNext.insert({nUse[cC].front(), cC});
contain[cC] = true;
tInsert[cC] = cC;
}
int cntRem = 0;
for (int i = 0; i < N; i++) {
int cC = C[i];
assert(nUse[cC].front() == i);
nUse[cC].pop();
// ps("at time", i, " cC: ", cC);
if (contain[cC]) {
// ps("contained");
allNext.erase({i, cC});
allNext.insert({nUse[cC].front(), cC});
used[tInsert[cC]] = true;
tInsert[cC] = i + K;
} else {
// ps("added");
cntRem++;
pi furtUse = *(--allNext.end());
allNext.erase(--allNext.end());
contain[furtUse.s] = false;
// ps("remove:", furtUse.s);
allNext.insert({nUse[cC].front(), cC});
contain[cC] = true;
tInsert[cC] = i + K;
}
}
// cout << "cntRem: " << cntRem << endl;
for (int i = 0; i < 2 * N; i++) {
WriteAdvice(used[i]);
}
}
#include <bits/stdc++.h>
#include "assistant.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
#define pb push_back
#define f first
#define s second
//namespace debug {
// const int DEBUG = true;
//
// template<class T1, class T2>
// void pr(const pair<T1, T2> &x);
//
// template<class T, size_t SZ>
// void pr(const array<T, SZ> &x);
//
// template<class T>
// void pr(const vector<T> &x);
//
// template<class T>
// void pr(const set<T> &x);
//
// template<class T1, class T2>
// void pr(const map<T1, T2> &x);
//
// template<class T>
// void pr(const T &x) { if (DEBUG) cout << x; }
//
// template<class T, class... Ts>
// void pr(const T &first, const Ts &... rest) { pr(first), pr(rest...); }
//
// template<class T1, class T2>
// void pr(const pair<T1, T2> &x) { pr("{", x.f, ", ", x.s, "}"); }
//
// template<class T>
// void prIn(const T &x) {
// pr("{");
// bool fst = 1;
// for (auto &a : x) {
// pr(fst ? "" : ", ", a), fst = 0;
// }
// pr("}");
// }
//
// template<class T, size_t SZ>
// void pr(const array<T, SZ> &x) { prIn(x); }
//
// template<class T>
// void pr(const vector<T> &x) { prIn(x); }
//
// template<class T>
// void pr(const set<T> &x) { prIn(x); }
//
// template<class T1, class T2>
// void pr(const map<T1, T2> &x) { prIn(x); }
//
// void ps() { pr("\n"), cout << flush; }
//
// template<class Arg, class... Args>
// void ps(const Arg &first, const Args &... rest) {
// pr(first, " ");
// ps(rest...);
// }
//}
//using namespace debug;
const int MAXN = 1e5;
void Assist(unsigned char *data, int N, int K, int R) {
queue<int> unused;
vi contain(N, 0);
// cout << "data ";
// for (int i = 0; i < 2 * N; i++) {
// cout << (data[i] == 1) << ", ";
// }
// cout << endl;
for (int i = 0; i < K; i++) {
if (data[i] == 0) {
unused.push(i);
// ps("push", i);
}
contain[i] = true;
}
for (int i = 0; i < N; i++) {
int cC = GetRequest();
if (contain[cC]) {
if (data[i + K] == 0) {
unused.push(cC);
// ps("push:", cC);
}
} else {
assert(unused.size() > 0);
int remC = unused.front();
unused.pop();
contain[remC] = false;
PutBack(remC);
contain[cC] = true;
if (data[i + K] == 0) {
unused.push(cC);
// ps("push:", cC);
}
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
135408 KB |
Output is correct |
2 |
Correct |
70 ms |
135224 KB |
Output is correct |
3 |
Correct |
72 ms |
135664 KB |
Output is correct |
4 |
Correct |
73 ms |
135560 KB |
Output is correct |
5 |
Correct |
88 ms |
135664 KB |
Output is correct |
6 |
Correct |
76 ms |
135664 KB |
Output is correct |
7 |
Correct |
75 ms |
135664 KB |
Output is correct |
8 |
Correct |
75 ms |
135664 KB |
Output is correct |
9 |
Correct |
75 ms |
135664 KB |
Output is correct |
10 |
Correct |
76 ms |
135840 KB |
Output is correct |
11 |
Correct |
75 ms |
135904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
82 ms |
135936 KB |
Output is correct |
2 |
Correct |
135 ms |
138480 KB |
Output is correct |
3 |
Correct |
230 ms |
144112 KB |
Output is correct |
4 |
Correct |
200 ms |
140784 KB |
Output is correct |
5 |
Correct |
195 ms |
140984 KB |
Output is correct |
6 |
Correct |
206 ms |
141296 KB |
Output is correct |
7 |
Correct |
228 ms |
142520 KB |
Output is correct |
8 |
Correct |
200 ms |
142224 KB |
Output is correct |
9 |
Correct |
180 ms |
140784 KB |
Output is correct |
10 |
Correct |
237 ms |
143856 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
197 ms |
141040 KB |
Output is correct |
2 |
Correct |
238 ms |
143088 KB |
Output is correct |
3 |
Correct |
236 ms |
143088 KB |
Output is correct |
4 |
Correct |
234 ms |
143344 KB |
Output is correct |
5 |
Correct |
228 ms |
142776 KB |
Output is correct |
6 |
Correct |
241 ms |
143096 KB |
Output is correct |
7 |
Correct |
233 ms |
143088 KB |
Output is correct |
8 |
Correct |
227 ms |
143088 KB |
Output is correct |
9 |
Correct |
230 ms |
143344 KB |
Output is correct |
10 |
Correct |
236 ms |
143088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
94 ms |
135488 KB |
Output is correct |
2 |
Correct |
76 ms |
135840 KB |
Output is correct |
3 |
Correct |
80 ms |
135592 KB |
Output is correct |
4 |
Correct |
74 ms |
135664 KB |
Output is correct |
5 |
Correct |
75 ms |
135664 KB |
Output is correct |
6 |
Correct |
75 ms |
135664 KB |
Output is correct |
7 |
Correct |
76 ms |
135664 KB |
Output is correct |
8 |
Correct |
77 ms |
135920 KB |
Output is correct |
9 |
Correct |
76 ms |
135904 KB |
Output is correct |
10 |
Correct |
77 ms |
135920 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
233 ms |
142064 KB |
Output is correct - 200000 bits used |
2 |
Correct |
236 ms |
142104 KB |
Output is correct - 200000 bits used |
3 |
Correct |
239 ms |
142064 KB |
Output is correct - 200000 bits used |
4 |
Correct |
243 ms |
141896 KB |
Output is correct - 200000 bits used |
5 |
Correct |
238 ms |
141808 KB |
Output is correct - 200000 bits used |
6 |
Correct |
273 ms |
142072 KB |
Output is correct - 200000 bits used |
7 |
Correct |
234 ms |
142160 KB |
Output is correct - 199678 bits used |
8 |
Correct |
235 ms |
142064 KB |
Output is correct - 200000 bits used |
9 |
Correct |
239 ms |
142064 KB |
Output is correct - 200000 bits used |
10 |
Correct |
229 ms |
141904 KB |
Output is correct - 200000 bits used |