#include <cstdio>
#include <vector>
#include <set>
#include <stack>
#include <algorithm>
#include "advisor.h"
#include <cstring>
#include <cassert>
#define X first
#define Y second
#define PB push_back
using namespace std;
typedef pair<int, int> pii;
const int N = 1e5 + 10;
int out[N], lst[N], dea[N];
stack<int> nxt[N];
set<pii> s;
void ComputeAdvice(int *c, int n, int k, int m) {
memset(lst, -1, sizeof(lst));
for(int i = 0; i < n; ++i) {
nxt[i].push(N);
}
for(int i = n - 1; i >= 0; --i) {
nxt[c[i]].push(i);
}
for(int i = 0; i < k; ++i) {
s.insert({nxt[i].top(), i});
}
for(int i = 0; i < n; ++i) {
auto it = s.lower_bound({nxt[c[i]].top(), c[i]});
nxt[c[i]].pop();
if(it != s.end() && it->Y == c[i]) {
out[i] = -1;
s.erase(it);
} else {
int obr = prev(s.end())->Y;
out[i] = obr;
dea[lst[obr]] = 1;
s.erase({nxt[obr].top(), obr});
}
s.insert({nxt[c[i]].top(), c[i]});
lst[c[i]] = i + k;
}
for(auto i : s) {
dea[lst[i.Y]] = 1;
}
for(int i = 0; i < k + n; ++i) {
WriteAdvice(dea[i]);
}
}
#include <cstdio>
#include <set>
#include "assistant.h"
#include <algorithm>
#include <cassert>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int N = 1e5 + 10;
// GetRequest()
// PutBack(int x)
set<int> act[2];
void Assist(unsigned char *a, int n, int k, int r) {
for(int i = 0; i < k; ++i) {
act[a[i]].insert(i);
}
for(int i = 0; i < n; ++i) {
int x = GetRequest();
bool d = a[i + k];
auto it = act[0].lower_bound(x);
if(it != act[0].end() && *it == x) {
act[0].erase(it);
} else {
int out = *act[1].begin();
act[1].erase(act[1].begin());
PutBack(out);
}
act[d].insert(x);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
95 ms |
137844 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
73 ms |
138164 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
125 ms |
142868 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
80 ms |
137992 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
158 ms |
142620 KB |
Execution killed with signal 11 |
2 |
Runtime error |
121 ms |
142720 KB |
Execution killed with signal 11 |
3 |
Runtime error |
145 ms |
143020 KB |
Execution killed with signal 11 |
4 |
Runtime error |
119 ms |
142980 KB |
Execution killed with signal 11 |
5 |
Runtime error |
129 ms |
142964 KB |
Execution killed with signal 11 |
6 |
Runtime error |
144 ms |
142928 KB |
Execution killed with signal 11 |
7 |
Runtime error |
117 ms |
142936 KB |
Execution killed with signal 11 |
8 |
Runtime error |
116 ms |
143020 KB |
Execution killed with signal 11 |
9 |
Runtime error |
119 ms |
142920 KB |
Execution killed with signal 11 |
10 |
Runtime error |
104 ms |
142928 KB |
Execution killed with signal 11 |