Submission #932730

# Submission time Handle Problem Language Result Execution time Memory
932730 2024-02-24T05:35:24 Z abcvuitunggio Beech Tree (IOI23_beechtree) C++17
28 / 100
1660 ms 154572 KB
#include "beechtree.h"
#include <bits/stdc++.h>
using namespace std;
const int lim=200001,mxn=1e7+1;
int n,m,p[lim][20],bad[lim],sz[lim],tin[lim],tout[lim],t,id,pos[lim],order[lim],root[lim][2],last[lim],cur;
int le[mxn],ri[mxn],st[mxn];
vector <int> c,res,ke[lim],ve[lim];
void dfs(int u){
    sz[u]=1;
    tin[u]=++t;
    for (int v:ke[u]){
        for (int i=1;i<20;i++)
            p[v][i]=(p[v][i-1]<0?-1:p[p[v][i-1]][i-1]);
        dfs(v);
        sz[u]+=sz[v];
    }
    tout[u]=t;
    ve[sz[u]].push_back(u);
}
void dfs2(int u){
    for (int v:ke[u]){
        dfs2(v);
        bad[u]|=bad[v];
    }
}
int update(int node, int l, int r, int i){
    cur++;
    if (l==r){
        st[cur]++;
        return cur;
    }
    int tmp=cur,mid=(l+r)>>1;
    le[tmp]=le[node];
    ri[tmp]=ri[node];
    if (mid<i)
        ri[tmp]=update(ri[node],mid+1,r,i);
    else
        le[tmp]=update(le[node],l,mid,i);
    st[tmp]=st[le[tmp]]+st[ri[tmp]];
    return tmp;
}
int get(int node, int l, int r, int u, int v){
    if (l>v||r<u||!node)
        return 0;
    if (l>=u&&r<=v)
        return st[node];
    int mid=(l+r)>>1;
    return get(le[node],l,mid,u,v)+get(ri[node],mid+1,r,u,v);
}
int get(int i, int j, int k){
    int res=get(root[i][k],1,n,tin[j],tout[j]);
    if (!k||c[i]==c[j])
        res--;
    return res-k;
}
vector <int> beechtree(int N, int M, vector<int> P, vector<int> C){
    n=N,m=M,c=C;
    for (int i=1;i<n;i++){
        ke[P[i]].push_back(i);
        p[i][0]=P[i];
    }
    p[0][0]=-1;
    dfs(0);
    for (int i=n;i>=0;i--){
        sort(ve[i].begin(),ve[i].end(),[](int u, int v){return pos[p[u][0]]<pos[p[v][0]];});
        for (int j:ve[i]){
            pos[j]=++id;
            order[id]=j;
        }
    }
    for (int i=1;i<=n;i++){
        int j=order[i];
        root[j][0]=update(root[order[i-1]][0],1,n,tin[j]);
        root[j][1]=update(last[c[j]],1,n,tin[j]);
        last[c[j]]=root[j][1];
    }
    for (int i=1;i<n;i++){
        int u=i;
        for (int j=19;j>=0;j--)
            if (p[u][j]>=0)
                if (get(i,p[u][j],1)==get(P[i],p[u][j],0))
                    u=p[u][j];
        if (p[u][0]>=0)
            bad[p[u][0]]=1;
    }
    dfs2(0);
    for (int i=0;i<n;i++)
        res.push_back(bad[i]^1);
    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16984 KB Output is correct
2 Correct 3 ms 16984 KB Output is correct
3 Correct 3 ms 16988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 17240 KB Output is correct
2 Correct 3 ms 16988 KB Output is correct
3 Correct 3 ms 16984 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 3 ms 17016 KB Output is correct
9 Correct 3 ms 16988 KB Output is correct
10 Correct 3 ms 16988 KB Output is correct
11 Correct 3 ms 16988 KB Output is correct
12 Correct 3 ms 16988 KB Output is correct
13 Correct 3 ms 16988 KB Output is correct
14 Correct 3 ms 16988 KB Output is correct
15 Correct 3 ms 16988 KB Output is correct
16 Correct 4 ms 17232 KB Output is correct
17 Correct 3 ms 16984 KB Output is correct
18 Correct 3 ms 17016 KB Output is correct
19 Correct 3 ms 16984 KB Output is correct
20 Correct 4 ms 16984 KB Output is correct
21 Correct 3 ms 17240 KB Output is correct
22 Correct 3 ms 16988 KB Output is correct
23 Correct 4 ms 16988 KB Output is correct
24 Correct 3 ms 16984 KB Output is correct
25 Correct 3 ms 16988 KB Output is correct
26 Correct 3 ms 16988 KB Output is correct
27 Correct 3 ms 16988 KB Output is correct
28 Correct 3 ms 16988 KB Output is correct
29 Correct 3 ms 16988 KB Output is correct
30 Correct 3 ms 16988 KB Output is correct
31 Correct 3 ms 16988 KB Output is correct
32 Correct 3 ms 16984 KB Output is correct
33 Correct 3 ms 16988 KB Output is correct
34 Correct 3 ms 16988 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 17240 KB Output is correct
2 Correct 3 ms 16988 KB Output is correct
3 Correct 3 ms 16984 KB Output is correct
4 Correct 3 ms 16988 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 798 ms 154472 KB Output is correct
8 Correct 763 ms 154572 KB Output is correct
9 Correct 4 ms 16988 KB Output is correct
10 Correct 4 ms 17016 KB Output is correct
11 Correct 4 ms 16988 KB Output is correct
12 Correct 4 ms 16984 KB Output is correct
13 Correct 6 ms 17752 KB Output is correct
14 Correct 7 ms 17756 KB Output is correct
15 Correct 8 ms 18268 KB Output is correct
16 Correct 8 ms 18268 KB Output is correct
17 Correct 449 ms 153512 KB Output is correct
18 Correct 838 ms 153804 KB Output is correct
19 Correct 737 ms 154492 KB Output is correct
20 Correct 876 ms 154528 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 16988 KB Output is correct
2 Incorrect 3 ms 16988 KB 2nd lines differ - on the 11th token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 17240 KB Output is correct
2 Correct 3 ms 16988 KB Output is correct
3 Correct 3 ms 16988 KB Output is correct
4 Correct 3 ms 17016 KB Output is correct
5 Correct 798 ms 154472 KB Output is correct
6 Correct 763 ms 154572 KB Output is correct
7 Correct 4 ms 16984 KB Output is correct
8 Correct 3 ms 16988 KB Output is correct
9 Correct 7 ms 18136 KB Output is correct
10 Correct 5 ms 18012 KB Output is correct
11 Correct 599 ms 133452 KB Output is correct
12 Incorrect 253 ms 122928 KB 2nd lines differ - on the 176894th token, expected: '0', found: '1'
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16984 KB Output is correct
2 Correct 3 ms 16984 KB Output is correct
3 Correct 3 ms 16988 KB Output is correct
4 Correct 3 ms 17240 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 3 ms 16984 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 3 ms 16988 KB Output is correct
9 Correct 3 ms 16988 KB Output is correct
10 Correct 3 ms 16988 KB Output is correct
11 Correct 3 ms 17016 KB Output is correct
12 Correct 3 ms 16988 KB Output is correct
13 Correct 3 ms 16988 KB Output is correct
14 Correct 3 ms 16988 KB Output is correct
15 Correct 3 ms 16988 KB Output is correct
16 Correct 3 ms 16988 KB Output is correct
17 Correct 3 ms 16988 KB Output is correct
18 Correct 3 ms 16988 KB Output is correct
19 Correct 4 ms 17232 KB Output is correct
20 Correct 3 ms 16984 KB Output is correct
21 Correct 3 ms 17016 KB Output is correct
22 Correct 3 ms 16984 KB Output is correct
23 Correct 4 ms 16984 KB Output is correct
24 Correct 3 ms 17240 KB Output is correct
25 Correct 3 ms 16988 KB Output is correct
26 Correct 4 ms 16988 KB Output is correct
27 Correct 3 ms 16984 KB Output is correct
28 Correct 3 ms 16988 KB Output is correct
29 Correct 3 ms 16988 KB Output is correct
30 Correct 3 ms 16988 KB Output is correct
31 Correct 3 ms 16988 KB Output is correct
32 Correct 3 ms 16988 KB Output is correct
33 Correct 3 ms 16988 KB Output is correct
34 Correct 3 ms 16988 KB Output is correct
35 Correct 3 ms 16984 KB Output is correct
36 Correct 3 ms 16988 KB Output is correct
37 Correct 3 ms 16988 KB Output is correct
38 Correct 4 ms 16988 KB Output is correct
39 Correct 4 ms 17016 KB Output is correct
40 Correct 4 ms 16988 KB Output is correct
41 Correct 4 ms 16984 KB Output is correct
42 Correct 4 ms 16988 KB Output is correct
43 Incorrect 3 ms 16988 KB 2nd lines differ - on the 11th token, expected: '0', found: '1'
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 17240 KB Output is correct
2 Correct 3 ms 16988 KB Output is correct
3 Correct 3 ms 16988 KB Output is correct
4 Correct 3 ms 17016 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 3 ms 16988 KB Output is correct
9 Correct 3 ms 16988 KB Output is correct
10 Correct 3 ms 16988 KB Output is correct
11 Correct 3 ms 16988 KB Output is correct
12 Correct 4 ms 17232 KB Output is correct
13 Correct 3 ms 16984 KB Output is correct
14 Correct 3 ms 17016 KB Output is correct
15 Correct 3 ms 16984 KB Output is correct
16 Correct 4 ms 16984 KB Output is correct
17 Correct 3 ms 17240 KB Output is correct
18 Correct 3 ms 16988 KB Output is correct
19 Correct 4 ms 16988 KB Output is correct
20 Correct 3 ms 16984 KB Output is correct
21 Correct 3 ms 16988 KB Output is correct
22 Correct 3 ms 16988 KB Output is correct
23 Correct 3 ms 16988 KB Output is correct
24 Correct 3 ms 16988 KB Output is correct
25 Correct 5 ms 17756 KB Output is correct
26 Correct 7 ms 17756 KB Output is correct
27 Correct 7 ms 17756 KB Output is correct
28 Correct 8 ms 17752 KB Output is correct
29 Correct 6 ms 18008 KB Output is correct
30 Correct 7 ms 17500 KB Output is correct
31 Correct 5 ms 17496 KB Output is correct
32 Correct 6 ms 17496 KB Output is correct
33 Correct 7 ms 17548 KB Output is correct
34 Correct 5 ms 17500 KB Output is correct
35 Correct 6 ms 17500 KB Output is correct
36 Correct 6 ms 17324 KB Output is correct
37 Correct 6 ms 17500 KB Output is correct
38 Correct 6 ms 17500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16984 KB Output is correct
2 Correct 3 ms 16984 KB Output is correct
3 Correct 3 ms 16988 KB Output is correct
4 Correct 3 ms 17240 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 3 ms 16984 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 3 ms 16988 KB Output is correct
9 Correct 3 ms 16988 KB Output is correct
10 Correct 3 ms 16988 KB Output is correct
11 Correct 3 ms 17016 KB Output is correct
12 Correct 3 ms 16988 KB Output is correct
13 Correct 3 ms 16988 KB Output is correct
14 Correct 3 ms 16988 KB Output is correct
15 Correct 3 ms 16988 KB Output is correct
16 Correct 3 ms 16988 KB Output is correct
17 Correct 3 ms 16988 KB Output is correct
18 Correct 3 ms 16988 KB Output is correct
19 Correct 4 ms 17232 KB Output is correct
20 Correct 3 ms 16984 KB Output is correct
21 Correct 3 ms 17016 KB Output is correct
22 Correct 3 ms 16984 KB Output is correct
23 Correct 4 ms 16984 KB Output is correct
24 Correct 3 ms 17240 KB Output is correct
25 Correct 3 ms 16988 KB Output is correct
26 Correct 4 ms 16988 KB Output is correct
27 Correct 3 ms 16984 KB Output is correct
28 Correct 3 ms 16988 KB Output is correct
29 Correct 3 ms 16988 KB Output is correct
30 Correct 3 ms 16988 KB Output is correct
31 Correct 3 ms 16988 KB Output is correct
32 Correct 3 ms 16988 KB Output is correct
33 Correct 3 ms 16988 KB Output is correct
34 Correct 3 ms 16988 KB Output is correct
35 Correct 3 ms 16984 KB Output is correct
36 Correct 3 ms 16988 KB Output is correct
37 Correct 3 ms 16988 KB Output is correct
38 Correct 4 ms 16988 KB Output is correct
39 Correct 4 ms 17016 KB Output is correct
40 Correct 4 ms 16988 KB Output is correct
41 Correct 4 ms 16984 KB Output is correct
42 Correct 6 ms 17752 KB Output is correct
43 Correct 7 ms 17756 KB Output is correct
44 Correct 8 ms 18268 KB Output is correct
45 Correct 8 ms 18268 KB Output is correct
46 Correct 4 ms 16988 KB Output is correct
47 Incorrect 3 ms 16988 KB 2nd lines differ - on the 11th token, expected: '0', found: '1'
48 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 17240 KB Output is correct
2 Correct 3 ms 16988 KB Output is correct
3 Correct 3 ms 16988 KB Output is correct
4 Correct 3 ms 17016 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 3 ms 16988 KB Output is correct
9 Correct 3 ms 16988 KB Output is correct
10 Correct 3 ms 16988 KB Output is correct
11 Correct 3 ms 16988 KB Output is correct
12 Correct 4 ms 17232 KB Output is correct
13 Correct 3 ms 16984 KB Output is correct
14 Correct 3 ms 17016 KB Output is correct
15 Correct 3 ms 16984 KB Output is correct
16 Correct 4 ms 16984 KB Output is correct
17 Correct 3 ms 17240 KB Output is correct
18 Correct 3 ms 16988 KB Output is correct
19 Correct 4 ms 16988 KB Output is correct
20 Correct 3 ms 16984 KB Output is correct
21 Correct 3 ms 16988 KB Output is correct
22 Correct 3 ms 16988 KB Output is correct
23 Correct 3 ms 16988 KB Output is correct
24 Correct 3 ms 16988 KB Output is correct
25 Correct 5 ms 17756 KB Output is correct
26 Correct 7 ms 17756 KB Output is correct
27 Correct 7 ms 17756 KB Output is correct
28 Correct 8 ms 17752 KB Output is correct
29 Correct 6 ms 18008 KB Output is correct
30 Correct 7 ms 17500 KB Output is correct
31 Correct 5 ms 17496 KB Output is correct
32 Correct 6 ms 17496 KB Output is correct
33 Correct 7 ms 17548 KB Output is correct
34 Correct 5 ms 17500 KB Output is correct
35 Correct 6 ms 17500 KB Output is correct
36 Correct 6 ms 17324 KB Output is correct
37 Correct 6 ms 17500 KB Output is correct
38 Correct 6 ms 17500 KB Output is correct
39 Correct 452 ms 153080 KB Output is correct
40 Correct 829 ms 153080 KB Output is correct
41 Correct 928 ms 153292 KB Output is correct
42 Correct 1103 ms 153080 KB Output is correct
43 Correct 462 ms 146300 KB Output is correct
44 Correct 797 ms 137240 KB Output is correct
45 Correct 511 ms 132928 KB Output is correct
46 Correct 790 ms 132952 KB Output is correct
47 Correct 538 ms 133304 KB Output is correct
48 Correct 1649 ms 133128 KB Output is correct
49 Incorrect 1660 ms 132364 KB 2nd lines differ - on the 185833rd token, expected: '0', found: '1'
50 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 16984 KB Output is correct
2 Correct 3 ms 16984 KB Output is correct
3 Correct 3 ms 16988 KB Output is correct
4 Correct 3 ms 17240 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 3 ms 16984 KB Output is correct
7 Correct 3 ms 16988 KB Output is correct
8 Correct 3 ms 16988 KB Output is correct
9 Correct 3 ms 16988 KB Output is correct
10 Correct 3 ms 16988 KB Output is correct
11 Correct 3 ms 17016 KB Output is correct
12 Correct 3 ms 16988 KB Output is correct
13 Correct 3 ms 16988 KB Output is correct
14 Correct 3 ms 16988 KB Output is correct
15 Correct 3 ms 16988 KB Output is correct
16 Correct 3 ms 16988 KB Output is correct
17 Correct 3 ms 16988 KB Output is correct
18 Correct 3 ms 16988 KB Output is correct
19 Correct 4 ms 17232 KB Output is correct
20 Correct 3 ms 16984 KB Output is correct
21 Correct 3 ms 17016 KB Output is correct
22 Correct 3 ms 16984 KB Output is correct
23 Correct 4 ms 16984 KB Output is correct
24 Correct 3 ms 17240 KB Output is correct
25 Correct 3 ms 16988 KB Output is correct
26 Correct 4 ms 16988 KB Output is correct
27 Correct 3 ms 16984 KB Output is correct
28 Correct 3 ms 16988 KB Output is correct
29 Correct 3 ms 16988 KB Output is correct
30 Correct 3 ms 16988 KB Output is correct
31 Correct 3 ms 16988 KB Output is correct
32 Correct 3 ms 16988 KB Output is correct
33 Correct 3 ms 16988 KB Output is correct
34 Correct 3 ms 16988 KB Output is correct
35 Correct 3 ms 16984 KB Output is correct
36 Correct 3 ms 16988 KB Output is correct
37 Correct 3 ms 16988 KB Output is correct
38 Correct 798 ms 154472 KB Output is correct
39 Correct 763 ms 154572 KB Output is correct
40 Correct 4 ms 16988 KB Output is correct
41 Correct 4 ms 17016 KB Output is correct
42 Correct 4 ms 16988 KB Output is correct
43 Correct 4 ms 16984 KB Output is correct
44 Correct 6 ms 17752 KB Output is correct
45 Correct 7 ms 17756 KB Output is correct
46 Correct 8 ms 18268 KB Output is correct
47 Correct 8 ms 18268 KB Output is correct
48 Correct 449 ms 153512 KB Output is correct
49 Correct 838 ms 153804 KB Output is correct
50 Correct 737 ms 154492 KB Output is correct
51 Correct 876 ms 154528 KB Output is correct
52 Correct 4 ms 16988 KB Output is correct
53 Incorrect 3 ms 16988 KB 2nd lines differ - on the 11th token, expected: '0', found: '1'
54 Halted 0 ms 0 KB -