This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include "advisor.h"
#define pb push_back
using namespace std;
const int MM = 2e6 + 5;
vector <int> st[MM];
bool onn[MM],val[MM],valk[MM];
void ComputeAdvice(int *C, int N, int K, int M) {
int n=N,k=K;
for (int i=N-1;i>=0;i--){
st[C[i]].pb(i);
}
set <pair<int,int> > stt;
for (int i=0;i<K;i++){
onn[i] = 1;
int val = 0;
if (!st[i].size()) val=1e9;
else val=st[i].back();
stt.insert({val,i});
}
int i;
vector <int> vec;
for (i = 0; i < N; i++) {
int req = C[i];
if (onn[req]) {
vec.pb(-1);
int val = 0;
if (!st[req].size()) val=1e9;
else val=st[req].back();
stt.erase(stt.find({val,req}));
while (st[req].size() && st[req].back() <= i){
st[req].pop_back();
}
val = 0;
if (!st[req].size()) val=1e9;
else val=st[req].back();
stt.insert({val,req});
continue;
}
int idx=(--stt.end())->second; stt.erase(--stt.end());
vec.pb(idx);
onn[idx] = 0;
onn[req] = 1;
while (st[req].size() && st[req].back() <= i){
st[req].pop_back();
}
int val = 0;
if (!st[req].size()) val=1e9;
else val=st[req].back();
stt.insert({val,req});
}
// cout<<"write "<<endl;
for (int i = 0; i < k; i++){
int x = i;
bool check = 0;
for (int j = 0; j < n; j++){
if (C[j] == x) break;
if (vec[j] == -1) continue;
if (vec[j] == x){
check=1;
break;
}
}
if (check) {
//meore taroze unda iyos
//jer washlaa
valk[i] = 1;
}
// cout<<valk[i]<<" ";
WriteAdvice(valk[i]);
}
for (int i = 0; i < n; i++){
int x = C[i];
bool check=0;
for (int j = i + 1; j < n; j++){
if (C[j] == x) break;
if (vec[j] == -1) continue;
if (vec[j] == x){
check=1;
break;
}
}
if (check) {
//meore taroze unda iyos
//jer washlaa
val[i] = 1;
}
// cout<<val[i]<<" ";
WriteAdvice(val[i]);
}
// cout<<endl;
// for (int i=0;i<k;i++){
// WriteAdvice(valk[i]);
// cout<<valk[i]<<" ";
// }
// cout<<endl;
//
// for (int i=0;i<n;i++){
// WriteAdvice(val[i]);
// cout<<val[i]<<" ";
// }
// cout<<endl;
}
#include <bits/stdc++.h>
#include "assistant.h"
#define pb push_back
using namespace std;
int CC[2000005];
bool on[2000005];
int vall[2000005],vallk[2000005];
void Assist(unsigned char *A, int N, int K, int R) {
int n=N;
int k=K;
// cout<<A[0]<<endl;
// cout<<"read "<<R<<": ";
// for (int i=0;i<R;i++)
// cout<<A[i]<<"^ ";
// cout<<endl;
for (int i = 0; i < k; i++)
vallk[i] = A[i];
for (int i=0;i<n;i++)
vall[i] = A[i+k];
vector <int> t2;
for (int i=0;i<k;i++){
if (!vallk[i]) on[i] = 1;
else t2.pb(i);
}
int i;
int l = 0;
for (i = 0; i < N; i++) {
int req = GetRequest();
if (on[req]){
if (!vall[i]) continue;
on[req] = 0;
t2.pb(req);
continue;
}
// cout<<"back "<<t2.back()<<endl;
PutBack(t2.back());
t2.pop_back();
if (!vall[i]){
on[req] = 1;
}else{
t2.pb(req);
}
}
}
Compilation message (stderr)
assistant.cpp: In function 'void Assist(unsigned char*, int, int, int)':
assistant.cpp:32:6: warning: unused variable 'l' [-Wunused-variable]
32 | int l = 0;
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |