Submission #365021

# Submission time Handle Problem Language Result Execution time Memory
365021 2021-02-10T18:44:12 Z qwerasdfzxcl Last supper (IOI12_supper) C++14
100 / 100
136 ms 12848 KB
#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> idx[100100];
int pt[100100], btpos[50050], bg[50050], bt[200200], bgidx[100100];
int tree[200200];

void ComputeAdvice(int *C, int N, int K, int M);
void WriteAdvice(unsigned char a);

int mx(int a, int b){
    if (idx[bg[a]][pt[bg[a]]]>idx[bg[b]][pt[bg[b]]]) return a;
    return b;
}

void build(int k){
    for (int i=k;i<2*k;i++) tree[i]=i-k;
    for (int i=k-1;i>0;i--) tree[i]=mx(tree[i<<1], tree[i<<1|1]);
}

void update(int p, int k){
    for (p += k;p>1;p>>=1) tree[p>>1]=mx(tree[p], tree[p^1]);
}

void ComputeAdvice(int *C, int N, int K, int M){
    for (int i=0;i<N;i++){
        idx[C[i]].push_back(i);
    }
    for (int i=0;i<N;i++) idx[i].push_back(1e9);
    for (int i=0;i<N;i++){
        bgidx[i]=-1;
    }
    for (int i=0;i<K;i++){
        bg[i]=i;
        bgidx[i]=i;
        btpos[i]=i;
    }
    build(K);
    for (int i=0;i<N;i++){
        if (bgidx[C[i]]!=-1){
            int tmp=bgidx[C[i]];
            bt[btpos[tmp]]=0;
            btpos[tmp]=K+i;
            pt[C[i]]++;
            update(tmp, K);
        }
        else{
            int tmp=tree[1];
            bt[btpos[tmp]]=1;
            btpos[tmp]=K+i;
            pt[C[i]]++;
            bgidx[bg[tmp]]=-1;
            bgidx[C[i]]=tmp;
            bg[tmp]=C[i];
            update(tmp, K);
        }
    }
    for (int i=0;i<N+K;i++){
        if (bt[i]==0) WriteAdvice(0);
        else WriteAdvice(1);
    }
}


/*#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;
queue<int> q;
int bg[100100];
int bgyes[100100];

void Assist(unsigned char *A, int N, int K, int R);
void PutBack(int T);
int GetRequest();

void Assist(unsigned char *A, int N, int K, int R){
    fill(bgyes, bgyes+N, -1);
    for (int i=0;i<K;i++){
        if (A[i]) q.push(i);
        bgyes[i]=i;
        bg[i]=i;
    }
    for (int i=0;i<N;i++){
        int tmp=GetRequest();
        if (bgyes[tmp]!=-1){
            if(A[K+i]) q.push(bgyes[tmp]);
            continue;
        }
        int idx=q.front();
        q.pop();
        PutBack(bg[idx]);
        bgyes[bg[idx]]=-1;
        bgyes[tmp]=idx;
        bg[idx]=tmp;
        if (A[K+i]) q.push(bgyes[tmp]);
    }
}*/

/*int main(){
    int c[100100]={0};
    int n, k;
    scanf("%d %d", &n, &k);
    for (int i=0;i<n;i++) scanf("%d", c+i);
    ComputeAdvice(c, n, k, 1000100);
}

void WriteAdvice(unsigned char a){
    if (a) printf("1 ");
    else printf("0 ");
}
*/
/*
int main(){
    unsigned char a[200200];
    int n, k, r;
    scanf("%d %d %d", &n, &k, &r);
    for (int i=0;i<r;i++){
        int tmp;
        scanf("%d", &tmp);
        if (tmp==0) a[i]=0;
        else a[i]=1;
    }
    Assist(a, n, k, r);
}
int timer=0, x[4]={2, 0, 3, 0};

int GetRequest(){
    timer++;
    return x[timer-1];
}

void PutBack(int abc){
    printf("%d ", abc);
}
*/
/*#include "advisor.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> idx[100100];
int pt[100100], btpos[50050], bg[50050], bt[200200], bgidx[100100];
int tree[200200];

void ComputeAdvice(int *C, int N, int K, int M);
void WriteAdvice(unsigned char a);

int mx(int a, int b){
    if (idx[bg[a]][pt[bg[a]]]>idx[bg[b]][pt[bg[b]]]) return a;
    return b;
}

void build(int k){
    for (int i=k;i<2*k;i++) tree[i]=i-k;
    for (int i=k-1;i>0;i--) tree[i]=mx(tree[i<<1], tree[i<<1|1]);
}

void update(int p, int k){
    for (p += k;p>1;p>>=1) tree[p>>1]=mx(tree[p], tree[p^1]);
}

void ComputeAdvice(int *C, int N, int K, int M){
    for (int i=0;i<N;i++){
        idx[C[i]].push_back(i);
    }
    for (int i=0;i<N;i++) idx[i].push_back(1e9);
    for (int i=0;i<N;i++){
        bgidx[i]=-1;
    }
    for (int i=0;i<K;i++){
        bg[i]=i;
        bgidx[i]=i;
        btpos[i]=i;
    }
    build(K);
    for (int i=0;i<N;i++){
        if (bgidx[C[i]]!=-1){
            int tmp=bgidx[C[i]];
            bt[btpos[tmp]]=0;
            btpos[tmp]=K+i;
            pt[C[i]]++;
            update(tmp, K);
        }
        else{
            int tmp=tree[1];
            bt[btpos[tmp]]=1;
            btpos[tmp]=K+i;
            pt[C[i]]++;
            bgidx[bg[tmp]]=-1;
            bgidx[C[i]]=tmp;
            bg[tmp]=C[i];
            update(tmp, K);
        }
    }
    for (int i=0;i<N+K;i++){
        if (bt[i]==0) WriteAdvice(0);
        else WriteAdvice(1);
    }
}*/


#include "assistant.h"
#include <bits/stdc++.h>
using namespace std;
queue<int> q;
int bg[100100];
int bgyes[100100];

void Assist(unsigned char *A, int N, int K, int R);
void PutBack(int T);
int GetRequest();

void Assist(unsigned char *A, int N, int K, int R){
    fill(bgyes, bgyes+N, -1);
    for (int i=0;i<K;i++){
        if (A[i]) q.push(i);
        bgyes[i]=i;
        bg[i]=i;
    }
    for (int i=0;i<N;i++){
        int tmp=GetRequest();
        if (bgyes[tmp]!=-1){
            if(A[K+i]) q.push(bgyes[tmp]);
            continue;
        }
        int idx=q.front();
        q.pop();
        PutBack(bg[idx]);
        bgyes[bg[idx]]=-1;
        bgyes[tmp]=idx;
        bg[idx]=tmp;
        if (A[K+i]) q.push(bgyes[tmp]);
    }
}

/*int main(){
    int c[100100]={0};
    int n, k;
    scanf("%d %d", &n, &k);
    for (int i=0;i<n;i++) scanf("%d", c+i);
    ComputeAdvice(c, n, k, 1000100);
}

void WriteAdvice(unsigned char a){
    if (a) printf("1 ");
    else printf("0 ");
}
*/
/*
int main(){
    unsigned char a[200200];
    int n, k, r;
    scanf("%d %d %d", &n, &k, &r);
    for (int i=0;i<r;i++){
        int tmp;
        scanf("%d", &tmp);
        if (tmp==0) a[i]=0;
        else a[i]=1;
    }
    Assist(a, n, k, r);
}
int timer=0, x[4]={2, 0, 3, 0};

int GetRequest(){
    timer++;
    return x[timer-1];
}

void PutBack(int abc){
    printf("%d ", abc);
}
*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3044 KB Output is correct
2 Correct 3 ms 3192 KB Output is correct
3 Correct 4 ms 3400 KB Output is correct
4 Correct 4 ms 3336 KB Output is correct
5 Correct 7 ms 3616 KB Output is correct
6 Correct 7 ms 3568 KB Output is correct
7 Correct 7 ms 3704 KB Output is correct
8 Correct 8 ms 3488 KB Output is correct
9 Correct 9 ms 3488 KB Output is correct
10 Correct 7 ms 3620 KB Output is correct
11 Correct 7 ms 3488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 4244 KB Output is correct
2 Correct 49 ms 7712 KB Output is correct
3 Correct 131 ms 12848 KB Output is correct
4 Correct 96 ms 11824 KB Output is correct
5 Correct 102 ms 11720 KB Output is correct
6 Correct 112 ms 11860 KB Output is correct
7 Correct 119 ms 12520 KB Output is correct
8 Correct 104 ms 11176 KB Output is correct
9 Correct 83 ms 11904 KB Output is correct
10 Correct 123 ms 12360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 96 ms 9620 KB Output is correct
2 Correct 132 ms 11596 KB Output is correct
3 Correct 135 ms 11632 KB Output is correct
4 Correct 124 ms 11576 KB Output is correct
5 Correct 114 ms 11192 KB Output is correct
6 Correct 122 ms 11576 KB Output is correct
7 Correct 131 ms 11324 KB Output is correct
8 Correct 125 ms 11380 KB Output is correct
9 Correct 114 ms 11580 KB Output is correct
10 Correct 128 ms 11452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 3508 KB Output is correct
2 Correct 9 ms 3592 KB Output is correct
3 Correct 6 ms 3592 KB Output is correct
4 Correct 7 ms 3464 KB Output is correct
5 Correct 7 ms 3336 KB Output is correct
6 Correct 7 ms 3336 KB Output is correct
7 Correct 7 ms 3464 KB Output is correct
8 Correct 7 ms 3592 KB Output is correct
9 Correct 7 ms 3592 KB Output is correct
10 Correct 11 ms 3712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 126 ms 11188 KB Output is correct - 120000 bits used
2 Correct 135 ms 11320 KB Output is correct - 122000 bits used
3 Correct 130 ms 11456 KB Output is correct - 125000 bits used
4 Correct 136 ms 11608 KB Output is correct - 125000 bits used
5 Correct 128 ms 11324 KB Output is correct - 125000 bits used
6 Correct 122 ms 11324 KB Output is correct - 125000 bits used
7 Correct 126 ms 11576 KB Output is correct - 124828 bits used
8 Correct 130 ms 11324 KB Output is correct - 124910 bits used
9 Correct 127 ms 11572 KB Output is correct - 125000 bits used
10 Correct 129 ms 11376 KB Output is correct - 125000 bits used