#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> tmp[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;
tmp[i] = used;
}
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> tmp[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++){
//for(auto x:ss) cout<<x<<" ";
//cout<<"\n";
//for(int i=0;i<r+k;i++) cout<<A[i]<<" ";
//cout<<"\n";
int cur = GetRequest();
A[r + k] = cur;
auto tt = ss.find(cur);
if(tt != ss.end()) continue;
while(l < r+k && !a[l]) l++;
//cout<<A[l]<<"\n";
PutBack(A[l]);
ss.erase(A[l]);
ss.insert(cur);
l++;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
7144 KB |
Output is correct |
2 |
Correct |
5 ms |
7140 KB |
Output is correct |
3 |
Correct |
9 ms |
11248 KB |
Output is correct |
4 |
Correct |
28 ms |
42716 KB |
Output is correct |
5 |
Correct |
64 ms |
105328 KB |
Output is correct |
6 |
Correct |
65 ms |
105376 KB |
Output is correct |
7 |
Correct |
65 ms |
105432 KB |
Output is correct |
8 |
Correct |
64 ms |
105632 KB |
Output is correct |
9 |
Correct |
66 ms |
105784 KB |
Output is correct |
10 |
Correct |
66 ms |
105736 KB |
Output is correct |
11 |
Correct |
67 ms |
105528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
140 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
143 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
46 ms |
70384 KB |
Output is correct |
2 |
Correct |
68 ms |
105836 KB |
Output is correct |
3 |
Correct |
64 ms |
105264 KB |
Output is correct |
4 |
Correct |
64 ms |
105392 KB |
Output is correct |
5 |
Correct |
68 ms |
105452 KB |
Output is correct |
6 |
Correct |
66 ms |
105264 KB |
Output is correct |
7 |
Correct |
66 ms |
105520 KB |
Output is correct |
8 |
Correct |
65 ms |
105520 KB |
Output is correct |
9 |
Correct |
67 ms |
105520 KB |
Output is correct |
10 |
Correct |
68 ms |
106164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
145 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Runtime error |
142 ms |
262144 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
3 |
Runtime error |
151 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
4 |
Runtime error |
147 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
5 |
Runtime error |
147 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
6 |
Runtime error |
147 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
7 |
Runtime error |
150 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
8 |
Runtime error |
148 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
9 |
Runtime error |
147 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
10 |
Runtime error |
147 ms |
262148 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |