#include <bits/stdc++.h>
#ifndef EVAL
#include "grader.cpp"
#endif
#include "advisor.h"
//#include "assistant.h"
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define fastios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vll vector<ll>
#define vii vector<int>
#define vpii vector<pii>
#define vpll vector<pll>
#define cnt(a)__builtin_popcount(a)
template<class T> bool umin(T& a, const T& b) {return a > b? a = b, true:false;}
template<class T> bool umax(T& a, const T& b) {return a < b? a = b, true:false;}
const int NN = 125005;
const int mod = 1e9+7;
const ll inf = 1e18;
const ld Pi = acos(-1);
int fir[NN];
vector<int> used, last;
//int a[NN];
pii a[NN];
void ComputeAdvice(int *c, int n, int k, int m){
used.assign(n, -1);
for(int i=n-1;i>=0;i--){
a[i] = {used[c[i]], c[i]};
used[c[i]] = i;
}
memset(fir, -1, sizeof fir);
for(int i=0;i<n;i++){
if(fir[c[i]] == -1) fir[c[i]] = i;
}
set<pii> ss;
used.assign(n, 0);
last.assign(n, -1);
for(int i=0;i<k;i++) { last[i] = i, used[i] = 1; ss.insert({fir[i] == -1 ? mod : fir[i], i}); }
vector<int> ans(n+k);
for(int i=0;i<n;i++){
//for(auto x:ss) cout<<x.ss<<" ";
//cout<<"\n";
pii cur = a[i];
if(cur.ff == -1) cur.ff = mod;
if(used[cur.ss]){
int tt = cur.ff;
cur.ff = i;
auto x = ss.lb(cur);
if(x != ss.end()){
ss.erase(x);
ss.insert({tt, cur.ss});
}
last[cur.ss] = i+k;
ans[i+k] = 0;
continue;
}
auto er = --ss.end();
used[(*er).ss] = 0;
used[cur.ss] = 1;
//cout<<last[(*er).ss]<<" ";
ans[last[(*er).ss]] = 1;
last[cur.ss] = i+k;
ss.erase(er);
ss.insert(cur);
}
//cout<<"\n";
//for(int i=0;i<n;i++) cout<<ans[i]<<" ";
//cout<<"\n";
for(int i=0;i<n+k;i++) WriteAdvice(ans[i]);
}
/*
9 3 1500000
4 3 1 5 2 4 1 1 2
12 3 1000
0 2 1 2 2 3 0 1 2 3 0 2
4 2 12
2 0 3 0
7 2 14
1 1 2 3 1 3 2
*/
#include <bits/stdc++.h>
#ifndef EVAL
#include "grader.cpp"
#endif
//#include "advisor.h"
#include "assistant.h"
using namespace std;
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ub upper_bound
#define lb lower_bound
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(),x.rend()
#define fastios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vll vector<ll>
#define vii vector<int>
#define vpii vector<pii>
#define vpll vector<pll>
#define cnt(a)__builtin_popcount(a)
template<class T> bool umin(T& a, const T& b) {return a > b? a = b, true:false;}
template<class T> bool umax(T& a, const T& b) {return a < b? a = b, true:false;}
const int NN = 125005;
const int mod = 1e9+7;
const ll inf = 1e18;
const ld Pi = acos(-1);
int fir[NN];
vector<int> used, last;
//int a[NN];
void Assist(unsigned char *a, int n, int k, int r) {
//int last = 0;
vector<int> A(n + k);
used.assign(n, 0);
set<int> ss;
for(int i=0;i<k;i++) ss.insert(i), used[i] =1;
for(int i=0;i<k;i++) A[i] = i;
for(int l = 0, r = 0; r < n; r++){
int cur = GetRequest();
A[r + k] = cur;
auto tt = ss.find(cur);
if(tt != ss.end()) continue;
while(l < r+k && !a[l]) l++;
PutBack(A[l]);
ss.erase(A[l]);
ss.insert(cur);
l++;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1260 KB |
Output is correct |
2 |
Correct |
2 ms |
1512 KB |
Output is correct |
3 |
Correct |
3 ms |
1388 KB |
Output is correct |
4 |
Correct |
4 ms |
1316 KB |
Output is correct |
5 |
Correct |
5 ms |
1544 KB |
Output is correct |
6 |
Correct |
6 ms |
1640 KB |
Output is correct |
7 |
Correct |
6 ms |
1672 KB |
Output is correct |
8 |
Correct |
5 ms |
1544 KB |
Output is correct |
9 |
Correct |
6 ms |
1544 KB |
Output is correct |
10 |
Correct |
7 ms |
1676 KB |
Output is correct |
11 |
Correct |
7 ms |
1544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
1964 KB |
Output is correct |
2 |
Correct |
57 ms |
4684 KB |
Output is correct |
3 |
Correct |
145 ms |
11132 KB |
Output is correct |
4 |
Correct |
87 ms |
7404 KB |
Output is correct |
5 |
Correct |
96 ms |
7572 KB |
Output is correct |
6 |
Correct |
117 ms |
8228 KB |
Output is correct |
7 |
Correct |
144 ms |
9500 KB |
Output is correct |
8 |
Correct |
107 ms |
9156 KB |
Output is correct |
9 |
Correct |
79 ms |
7216 KB |
Output is correct |
10 |
Correct |
151 ms |
10572 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
113 ms |
7332 KB |
Output is correct |
2 |
Correct |
142 ms |
9888 KB |
Output is correct |
3 |
Correct |
146 ms |
10132 KB |
Output is correct |
4 |
Correct |
142 ms |
10132 KB |
Output is correct |
5 |
Correct |
133 ms |
9492 KB |
Output is correct |
6 |
Correct |
147 ms |
10200 KB |
Output is correct |
7 |
Correct |
142 ms |
10148 KB |
Output is correct |
8 |
Correct |
125 ms |
10128 KB |
Output is correct |
9 |
Correct |
126 ms |
10200 KB |
Output is correct |
10 |
Correct |
146 ms |
10200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1540 KB |
Output is correct |
2 |
Correct |
6 ms |
1544 KB |
Output is correct |
3 |
Correct |
5 ms |
1544 KB |
Output is correct |
4 |
Correct |
5 ms |
1544 KB |
Output is correct |
5 |
Correct |
6 ms |
1640 KB |
Output is correct |
6 |
Correct |
6 ms |
1636 KB |
Output is correct |
7 |
Correct |
8 ms |
1544 KB |
Output is correct |
8 |
Correct |
7 ms |
1760 KB |
Output is correct |
9 |
Correct |
7 ms |
1544 KB |
Output is correct |
10 |
Correct |
8 ms |
1808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
138 ms |
8412 KB |
Output is correct - 120000 bits used |
2 |
Correct |
141 ms |
8404 KB |
Output is correct - 122000 bits used |
3 |
Correct |
143 ms |
8780 KB |
Output is correct - 125000 bits used |
4 |
Correct |
146 ms |
9044 KB |
Output is correct - 125000 bits used |
5 |
Correct |
149 ms |
9012 KB |
Output is correct - 125000 bits used |
6 |
Correct |
147 ms |
8780 KB |
Output is correct - 125000 bits used |
7 |
Correct |
142 ms |
8916 KB |
Output is correct - 124828 bits used |
8 |
Correct |
144 ms |
8784 KB |
Output is correct - 124910 bits used |
9 |
Correct |
144 ms |
8944 KB |
Output is correct - 125000 bits used |
10 |
Correct |
126 ms |
9272 KB |
Output is correct - 125000 bits used |