#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define ALL(i) i.begin(), i.end()
#define SZ(i) int(i.size())
#define X first
#define Y second
#ifdef tmd
#define debug(...) fprintf(stderr,"#%d-(%s)=",__LINE__,#__VA_ARGS__);_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y) {cerr<<x<<",";_do(y...);}
template<typename IT> ostream& __printRng (ostream& os, IT bg, IT ed) {
for (IT it=bg;it!=ed;it++) {
if (it == bg) os << "{" << *it;
else os << "," << *it;
}
return os << "}";
}
template<typename T> ostream& operator << (ostream& os, const vector<T> &vec) {
return __printRng(os, ALL(vec));
}
template<typename T, typename S> ostream& operator << (ostream& os, const pair<T,S> &pa) {
return os << "{" << pa.X << "," << pa.Y << "}";
}
#else
#define debug(...)
#endif
#include "advisor.h"
const int BB = 25001;
void ComputeAdvice(int *c, int n, int k, int m) {
vector<int> nxt(n);
vector<int> lst(n, n);
for (int i=n-1; i>=0; i--) {
nxt[i] = lst[c[i]];
lst[c[i]] = i;
}
vector<int> CC;
for (int i=0; i<n; i++) {
CC.emplace_back(c[i]);
}
debug(CC);
set<pii> pq;
set<int> st;
map<int,int> pos;
vector<int> in(n);
vector<int> del(n+k);
for (int i=0; i<k; i++) {
pos[i] = i;
pq.emplace(pii(lst[i], i));
st.insert(i);
debug(lst[i], i);
in[i] = i;
}
vector<int> pl(k);
iota(pl.begin(), pl.end(), 0);
int prv = -1;
for (int i=0; i<n; i++) {
int req = c[i];
assert(c[i] == req);
bool flag = true;
if (!st.count(req)) {
pii cur = *prev(pq.end());
pq.erase(prev(pq.end()));
debug(cur.Y);
del[in[cur.Y]] = true;
pl[pos[cur.Y]] = req;
pos[req] = pos[cur.Y];
st.erase(cur.Y);
st.insert(req);
pq.emplace(nxt[i], req);
in[req] = i+k;
} else {
flag = false;
pq.erase({i, req});
pq.emplace(nxt[i], req);
in[req] = i+k;
}
}
for (int i=0; i<k+n; i++) {
WriteAdvice(del[i]);
}
debug("done");
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define ALL(i) i.begin(), i.end()
#define SZ(i) int(i.size())
#define X first
#define Y second
#ifdef tmd
#define debug(...) fprintf(stderr,"#%d-(%s)=",__LINE__,#__VA_ARGS__);_do(__VA_ARGS__);
template<typename T> void _do(T &&x){cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T &&x, S &&...y) {cerr<<x<<",";_do(y...);}
template<typename IT> ostream& __printRng (ostream& os, IT bg, IT ed) {
for (IT it=bg;it!=ed;it++) {
if (it == bg) os << "{" << *it;
else os << "," << *it;
}
return os << "}";
}
template<typename T> ostream& operator << (ostream& os, const vector<T> &vec) {
return __printRng(os, ALL(vec));
}
template<typename T, typename S> ostream& operator << (ostream& os, const pair<T,S> &pa) {
return os << "{" << pa.X << "," << pa.Y << "}";
}
#else
#define debug(...)
#endif
#include "assistant.h"
const int BB = 25001;
void Assist(unsigned char *a, int n, int k, int r) {
int prv = -1;
set<int> dl;
set<int> pl;
for (int i=0; i<k; i++) {
if (a[i]) dl.insert(i);
pl.insert(i);
}
vector<int> he;
for (int i=0; i<n+k; i++) {
he.emplace_back(a[i]);
}
debug(he);
for (int i=0, ptr=0; i<n; i++) {
int req = GetRequest();
debug(i, req);
if (pl.count(req)) {
if (a[i+k]) dl.insert(req);
continue;
} else {
assert(dl.size());
int tp = *dl.begin();
dl.erase(dl.begin());
pl.erase(tp);
pl.insert(req);
PutBack(tp);
if (a[i+k]) dl.insert(req);
}
}
}
Compilation message
advisor.cpp: In function 'void ComputeAdvice(int*, int, int, int)':
advisor.cpp:68:14: warning: variable 'flag' set but not used [-Wunused-but-set-variable]
68 | bool flag = true;
| ^~~~
advisor.cpp:63:9: warning: unused variable 'prv' [-Wunused-variable]
63 | int prv = -1;
| ^~~
assistant.cpp: In function 'void Assist(unsigned char*, int, int, int)':
assistant.cpp:50:19: warning: unused variable 'ptr' [-Wunused-variable]
50 | for (int i=0, ptr=0; i<n; i++) {
| ^~~
assistant.cpp:36:9: warning: unused variable 'prv' [-Wunused-variable]
36 | int prv = -1;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
780 KB |
Output is correct |
2 |
Correct |
2 ms |
896 KB |
Output is correct |
3 |
Correct |
3 ms |
1024 KB |
Output is correct |
4 |
Correct |
5 ms |
808 KB |
Output is correct |
5 |
Correct |
9 ms |
1304 KB |
Output is correct |
6 |
Correct |
11 ms |
1280 KB |
Output is correct |
7 |
Correct |
8 ms |
1280 KB |
Output is correct |
8 |
Correct |
9 ms |
1536 KB |
Output is correct |
9 |
Correct |
12 ms |
1536 KB |
Output is correct |
10 |
Correct |
12 ms |
1792 KB |
Output is correct |
11 |
Correct |
11 ms |
1536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
2304 KB |
Output is correct |
2 |
Correct |
105 ms |
6120 KB |
Output is correct |
3 |
Correct |
331 ms |
22240 KB |
Output is correct |
4 |
Correct |
194 ms |
12520 KB |
Output is correct |
5 |
Correct |
205 ms |
12776 KB |
Output is correct |
6 |
Correct |
271 ms |
14048 KB |
Output is correct |
7 |
Correct |
302 ms |
17376 KB |
Output is correct |
8 |
Correct |
220 ms |
18656 KB |
Output is correct |
9 |
Correct |
134 ms |
7136 KB |
Output is correct |
10 |
Correct |
304 ms |
19680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
232 ms |
14816 KB |
Output is correct |
2 |
Correct |
297 ms |
18400 KB |
Output is correct |
3 |
Correct |
298 ms |
19168 KB |
Output is correct |
4 |
Correct |
292 ms |
18144 KB |
Output is correct |
5 |
Correct |
247 ms |
15584 KB |
Output is correct |
6 |
Correct |
304 ms |
18656 KB |
Output is correct |
7 |
Correct |
294 ms |
18656 KB |
Output is correct |
8 |
Correct |
259 ms |
21224 KB |
Output is correct |
9 |
Correct |
222 ms |
16352 KB |
Output is correct |
10 |
Correct |
308 ms |
18656 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
1580 KB |
Output is correct |
2 |
Correct |
9 ms |
1792 KB |
Output is correct |
3 |
Correct |
8 ms |
1244 KB |
Output is correct |
4 |
Correct |
7 ms |
1280 KB |
Output is correct |
5 |
Correct |
9 ms |
1280 KB |
Output is correct |
6 |
Correct |
9 ms |
1280 KB |
Output is correct |
7 |
Correct |
10 ms |
1588 KB |
Output is correct |
8 |
Correct |
10 ms |
1536 KB |
Output is correct |
9 |
Correct |
10 ms |
1536 KB |
Output is correct |
10 |
Correct |
11 ms |
2048 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
303 ms |
17704 KB |
Output is correct - 120000 bits used |
2 |
Correct |
294 ms |
18144 KB |
Output is correct - 122000 bits used |
3 |
Correct |
305 ms |
18656 KB |
Output is correct - 125000 bits used |
4 |
Correct |
306 ms |
18656 KB |
Output is correct - 125000 bits used |
5 |
Correct |
298 ms |
18656 KB |
Output is correct - 125000 bits used |
6 |
Correct |
306 ms |
18656 KB |
Output is correct - 125000 bits used |
7 |
Correct |
299 ms |
18656 KB |
Output is correct - 124828 bits used |
8 |
Correct |
299 ms |
18656 KB |
Output is correct - 124910 bits used |
9 |
Correct |
294 ms |
18656 KB |
Output is correct - 125000 bits used |
10 |
Correct |
273 ms |
20960 KB |
Output is correct - 125000 bits used |