답안 #932731

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
932731 2024-02-24T05:40:11 Z abcvuitunggio 참나무 (IOI23_beechtree) C++17
28 / 100
1558 ms 152140 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])-1;
    return res-(k&&c[i]==c[j]);
}
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 (u)
            bad[p[u][0]]=1;
    }
    dfs2(0);
    for (int i=0;i<n;i++)
        res.push_back(bad[i]^1);
    return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16984 KB Output is correct
2 Correct 4 ms 16984 KB Output is correct
3 Correct 5 ms 16988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 17496 KB Output is correct
2 Correct 3 ms 16988 KB Output is correct
3 Correct 4 ms 16988 KB Output is correct
4 Correct 4 ms 16984 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 4 ms 16996 KB Output is correct
10 Correct 4 ms 16988 KB Output is correct
11 Correct 4 ms 16988 KB Output is correct
12 Correct 3 ms 16988 KB Output is correct
13 Correct 4 ms 16988 KB Output is correct
14 Correct 4 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 3 ms 16988 KB Output is correct
20 Correct 4 ms 16988 KB Output is correct
21 Correct 3 ms 16988 KB Output is correct
22 Correct 4 ms 17036 KB Output is correct
23 Correct 4 ms 16988 KB Output is correct
24 Correct 4 ms 16988 KB Output is correct
25 Correct 4 ms 16988 KB Output is correct
26 Correct 4 ms 16988 KB Output is correct
27 Correct 3 ms 16988 KB Output is correct
28 Correct 4 ms 17004 KB Output is correct
29 Correct 3 ms 16988 KB Output is correct
30 Correct 4 ms 16988 KB Output is correct
31 Correct 4 ms 16984 KB Output is correct
32 Correct 4 ms 16988 KB Output is correct
33 Correct 3 ms 16988 KB Output is correct
34 Correct 4 ms 16988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 17496 KB Output is correct
2 Correct 3 ms 16988 KB Output is correct
3 Correct 4 ms 16988 KB Output is correct
4 Correct 4 ms 16984 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 3 ms 16988 KB Output is correct
7 Correct 784 ms 151832 KB Output is correct
8 Correct 777 ms 152008 KB Output is correct
9 Correct 4 ms 16988 KB Output is correct
10 Correct 3 ms 16984 KB Output is correct
11 Correct 4 ms 16988 KB Output is correct
12 Correct 3 ms 17080 KB Output is correct
13 Correct 6 ms 17756 KB Output is correct
14 Correct 8 ms 17756 KB Output is correct
15 Correct 8 ms 18268 KB Output is correct
16 Correct 10 ms 18520 KB Output is correct
17 Correct 462 ms 151428 KB Output is correct
18 Correct 856 ms 151604 KB Output is correct
19 Correct 745 ms 152140 KB Output is correct
20 Correct 807 ms 152000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16988 KB Output is correct
2 Incorrect 3 ms 17000 KB 2nd lines differ - on the 11th token, expected: '0', found: '1'
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 17496 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 16988 KB Output is correct
5 Correct 784 ms 151832 KB Output is correct
6 Correct 777 ms 152008 KB Output is correct
7 Correct 4 ms 16988 KB Output is correct
8 Correct 6 ms 16988 KB Output is correct
9 Correct 8 ms 18080 KB Output is correct
10 Correct 6 ms 18012 KB Output is correct
11 Correct 618 ms 131076 KB Output is correct
12 Incorrect 270 ms 120636 KB 2nd lines differ - on the 176894th token, expected: '0', found: '1'
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16984 KB Output is correct
2 Correct 4 ms 16984 KB Output is correct
3 Correct 5 ms 16988 KB Output is correct
4 Correct 3 ms 17496 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 4 ms 16988 KB Output is correct
7 Correct 4 ms 16984 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 16996 KB Output is correct
13 Correct 4 ms 16988 KB Output is correct
14 Correct 4 ms 16988 KB Output is correct
15 Correct 3 ms 16988 KB Output is correct
16 Correct 4 ms 16988 KB Output is correct
17 Correct 4 ms 16988 KB Output is correct
18 Correct 3 ms 16988 KB Output is correct
19 Correct 3 ms 16988 KB Output is correct
20 Correct 3 ms 16988 KB Output is correct
21 Correct 3 ms 16988 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 16988 KB Output is correct
25 Correct 4 ms 17036 KB Output is correct
26 Correct 4 ms 16988 KB Output is correct
27 Correct 4 ms 16988 KB Output is correct
28 Correct 4 ms 16988 KB Output is correct
29 Correct 4 ms 16988 KB Output is correct
30 Correct 3 ms 16988 KB Output is correct
31 Correct 4 ms 17004 KB Output is correct
32 Correct 3 ms 16988 KB Output is correct
33 Correct 4 ms 16988 KB Output is correct
34 Correct 4 ms 16984 KB Output is correct
35 Correct 4 ms 16988 KB Output is correct
36 Correct 3 ms 16988 KB Output is correct
37 Correct 4 ms 16988 KB Output is correct
38 Correct 4 ms 16988 KB Output is correct
39 Correct 3 ms 16984 KB Output is correct
40 Correct 4 ms 16988 KB Output is correct
41 Correct 3 ms 17080 KB Output is correct
42 Correct 3 ms 16988 KB Output is correct
43 Incorrect 3 ms 17000 KB 2nd lines differ - on the 11th token, expected: '0', found: '1'
44 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 17496 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 16988 KB Output is correct
5 Correct 4 ms 16996 KB Output is correct
6 Correct 4 ms 16988 KB Output is correct
7 Correct 4 ms 16988 KB Output is correct
8 Correct 3 ms 16988 KB Output is correct
9 Correct 4 ms 16988 KB Output is correct
10 Correct 4 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 16988 KB Output is correct
17 Correct 3 ms 16988 KB Output is correct
18 Correct 4 ms 17036 KB Output is correct
19 Correct 4 ms 16988 KB Output is correct
20 Correct 4 ms 16988 KB Output is correct
21 Correct 4 ms 16988 KB Output is correct
22 Correct 4 ms 16988 KB Output is correct
23 Correct 3 ms 16988 KB Output is correct
24 Correct 4 ms 17004 KB Output is correct
25 Correct 6 ms 17752 KB Output is correct
26 Correct 7 ms 17752 KB Output is correct
27 Correct 8 ms 17756 KB Output is correct
28 Correct 8 ms 17756 KB Output is correct
29 Correct 6 ms 17588 KB Output is correct
30 Correct 7 ms 17500 KB Output is correct
31 Correct 8 ms 17496 KB Output is correct
32 Correct 9 ms 17500 KB Output is correct
33 Correct 8 ms 17496 KB Output is correct
34 Correct 6 ms 17500 KB Output is correct
35 Correct 6 ms 17500 KB Output is correct
36 Correct 5 ms 17500 KB Output is correct
37 Correct 5 ms 17500 KB Output is correct
38 Correct 7 ms 17496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16984 KB Output is correct
2 Correct 4 ms 16984 KB Output is correct
3 Correct 5 ms 16988 KB Output is correct
4 Correct 3 ms 17496 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 4 ms 16988 KB Output is correct
7 Correct 4 ms 16984 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 16996 KB Output is correct
13 Correct 4 ms 16988 KB Output is correct
14 Correct 4 ms 16988 KB Output is correct
15 Correct 3 ms 16988 KB Output is correct
16 Correct 4 ms 16988 KB Output is correct
17 Correct 4 ms 16988 KB Output is correct
18 Correct 3 ms 16988 KB Output is correct
19 Correct 3 ms 16988 KB Output is correct
20 Correct 3 ms 16988 KB Output is correct
21 Correct 3 ms 16988 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 16988 KB Output is correct
25 Correct 4 ms 17036 KB Output is correct
26 Correct 4 ms 16988 KB Output is correct
27 Correct 4 ms 16988 KB Output is correct
28 Correct 4 ms 16988 KB Output is correct
29 Correct 4 ms 16988 KB Output is correct
30 Correct 3 ms 16988 KB Output is correct
31 Correct 4 ms 17004 KB Output is correct
32 Correct 3 ms 16988 KB Output is correct
33 Correct 4 ms 16988 KB Output is correct
34 Correct 4 ms 16984 KB Output is correct
35 Correct 4 ms 16988 KB Output is correct
36 Correct 3 ms 16988 KB Output is correct
37 Correct 4 ms 16988 KB Output is correct
38 Correct 4 ms 16988 KB Output is correct
39 Correct 3 ms 16984 KB Output is correct
40 Correct 4 ms 16988 KB Output is correct
41 Correct 3 ms 17080 KB Output is correct
42 Correct 6 ms 17756 KB Output is correct
43 Correct 8 ms 17756 KB Output is correct
44 Correct 8 ms 18268 KB Output is correct
45 Correct 10 ms 18520 KB Output is correct
46 Correct 3 ms 16988 KB Output is correct
47 Incorrect 3 ms 17000 KB 2nd lines differ - on the 11th token, expected: '0', found: '1'
48 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 17496 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 16988 KB Output is correct
5 Correct 4 ms 16996 KB Output is correct
6 Correct 4 ms 16988 KB Output is correct
7 Correct 4 ms 16988 KB Output is correct
8 Correct 3 ms 16988 KB Output is correct
9 Correct 4 ms 16988 KB Output is correct
10 Correct 4 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 16988 KB Output is correct
17 Correct 3 ms 16988 KB Output is correct
18 Correct 4 ms 17036 KB Output is correct
19 Correct 4 ms 16988 KB Output is correct
20 Correct 4 ms 16988 KB Output is correct
21 Correct 4 ms 16988 KB Output is correct
22 Correct 4 ms 16988 KB Output is correct
23 Correct 3 ms 16988 KB Output is correct
24 Correct 4 ms 17004 KB Output is correct
25 Correct 6 ms 17752 KB Output is correct
26 Correct 7 ms 17752 KB Output is correct
27 Correct 8 ms 17756 KB Output is correct
28 Correct 8 ms 17756 KB Output is correct
29 Correct 6 ms 17588 KB Output is correct
30 Correct 7 ms 17500 KB Output is correct
31 Correct 8 ms 17496 KB Output is correct
32 Correct 9 ms 17500 KB Output is correct
33 Correct 8 ms 17496 KB Output is correct
34 Correct 6 ms 17500 KB Output is correct
35 Correct 6 ms 17500 KB Output is correct
36 Correct 5 ms 17500 KB Output is correct
37 Correct 5 ms 17500 KB Output is correct
38 Correct 7 ms 17496 KB Output is correct
39 Correct 483 ms 151424 KB Output is correct
40 Correct 795 ms 151464 KB Output is correct
41 Correct 986 ms 151420 KB Output is correct
42 Correct 1010 ms 151504 KB Output is correct
43 Correct 482 ms 144872 KB Output is correct
44 Correct 797 ms 135736 KB Output is correct
45 Correct 528 ms 131404 KB Output is correct
46 Correct 766 ms 131296 KB Output is correct
47 Correct 534 ms 131296 KB Output is correct
48 Correct 1558 ms 131228 KB Output is correct
49 Incorrect 1523 ms 130860 KB 2nd lines differ - on the 185833rd token, expected: '0', found: '1'
50 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 16984 KB Output is correct
2 Correct 4 ms 16984 KB Output is correct
3 Correct 5 ms 16988 KB Output is correct
4 Correct 3 ms 17496 KB Output is correct
5 Correct 3 ms 16988 KB Output is correct
6 Correct 4 ms 16988 KB Output is correct
7 Correct 4 ms 16984 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 16996 KB Output is correct
13 Correct 4 ms 16988 KB Output is correct
14 Correct 4 ms 16988 KB Output is correct
15 Correct 3 ms 16988 KB Output is correct
16 Correct 4 ms 16988 KB Output is correct
17 Correct 4 ms 16988 KB Output is correct
18 Correct 3 ms 16988 KB Output is correct
19 Correct 3 ms 16988 KB Output is correct
20 Correct 3 ms 16988 KB Output is correct
21 Correct 3 ms 16988 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 16988 KB Output is correct
25 Correct 4 ms 17036 KB Output is correct
26 Correct 4 ms 16988 KB Output is correct
27 Correct 4 ms 16988 KB Output is correct
28 Correct 4 ms 16988 KB Output is correct
29 Correct 4 ms 16988 KB Output is correct
30 Correct 3 ms 16988 KB Output is correct
31 Correct 4 ms 17004 KB Output is correct
32 Correct 3 ms 16988 KB Output is correct
33 Correct 4 ms 16988 KB Output is correct
34 Correct 4 ms 16984 KB Output is correct
35 Correct 4 ms 16988 KB Output is correct
36 Correct 3 ms 16988 KB Output is correct
37 Correct 4 ms 16988 KB Output is correct
38 Correct 784 ms 151832 KB Output is correct
39 Correct 777 ms 152008 KB Output is correct
40 Correct 4 ms 16988 KB Output is correct
41 Correct 3 ms 16984 KB Output is correct
42 Correct 4 ms 16988 KB Output is correct
43 Correct 3 ms 17080 KB Output is correct
44 Correct 6 ms 17756 KB Output is correct
45 Correct 8 ms 17756 KB Output is correct
46 Correct 8 ms 18268 KB Output is correct
47 Correct 10 ms 18520 KB Output is correct
48 Correct 462 ms 151428 KB Output is correct
49 Correct 856 ms 151604 KB Output is correct
50 Correct 745 ms 152140 KB Output is correct
51 Correct 807 ms 152000 KB Output is correct
52 Correct 3 ms 16988 KB Output is correct
53 Incorrect 3 ms 17000 KB 2nd lines differ - on the 11th token, expected: '0', found: '1'
54 Halted 0 ms 0 KB -