QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#401204#946. Magic Treesichengzhou#0 83ms20524kbC++144.0kb2024-04-28 08:06:102024-04-28 08:06:18

Judging History

你现在查看的是最新测评结果

  • [2024-04-28 08:06:18]
  • 评测
  • 测评结果:0
  • 用时:83ms
  • 内存:20524kb
  • [2024-04-28 08:06:10]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e5+5,M=22;
int n,m,K,fa[N],d[N],w[N];
struct Edge{
    int v,nxt;
}e[N];
int h[N],tot1;
void addEdge(int u,int v)
{
    tot1++;
    e[tot1].v=v;e[tot1].nxt=h[u];
    h[u]=tot1;
}
struct Seg{
    int l,r;
    LL val,mx,lz;
}t[N*18];
int rt[N],tot;
void update(int p)
{
    t[p].val=max(t[t[p].l].val,t[t[p].r].val);
}
void pushlz(int p,LL z)
{
    t[p].mx+=z;
    t[p].lz+=z;
    t[p].val+=z;
}
void pushmx(int p,LL z)
{
    t[p].mx=max(t[p].mx,z);
    t[p].val=max(t[p].val,z);
}
void lzdown(int p)
{
    if(t[p].l)
    {
        pushlz(t[p].l,t[p].lz);
        pushmx(t[p].l,t[p].mx);
    }
    if(t[p].r)
    {
        pushlz(t[p].r,t[p].lz);
        pushmx(t[p].r,t[p].mx);
    }
    t[p].mx=0;t[p].lz=0;
}
LL val;
void insert(int &p,int l,int r,int x,LL y)
{
    if(p==0)
    {
        p=++tot;
    }
//    cout<<p<<' '<<l<<' '<<r<<endl;
    if(l==r)
    {
        t[p].val+=y;
        val=t[p].val;
        return ;
    }
    lzdown(p);
    int mid=l+r>>1;
    if(x<=mid)
    {
        insert(t[p].l,l,mid,x,y);
    }else{
        insert(t[p].r,mid+1,r,x,y);
    }
    update(p);
}
void change(int p,int l,int r,int x,int y,LL z)
{
    if(x<=l&&r<=y)
    {
        if(l==r)
        {
            pushmx(p,z);
            return ;
        }
        lzdown(p);
        int mid=l+r>>1;
        if(t[p].l==0)
        {
            change(t[p].r,mid+1,r,x,y,z);
        }else if(t[p].r==0){
            change(t[p].l,l,mid,x,y,z);
        }else if(t[t[p].l].val<z)
        {
            pushmx(t[p].l,z);
            change(t[p].r,mid+1,r,x,y,z);
        }else{
            change(t[p].l,l,mid,x,y,z);
        }
        return ;
    }
    lzdown(p);
    int mid=l+r>>1;
    if(x<=mid&&t[p].l)
    {
        change(t[p].l,l,mid,x,y,z);
    }
    if(mid+1<=y&&t[p].r)
    {
        change(t[p].r,mid+1,r,x,y,z);
    }
    update(p);
}
void merge(int &x,int y,int l,int r,LL vx,LL vy)
{
    if(x==0)
    {
        x=y;pushlz(x,vx);
    //    cout<<x<<'&'<<t[x].val<<' '<<l<<' '<<r<<endl;
        return ;
    }
    if(y==0)
    {
        pushlz(x,vy);
    //    cout<<x<<'&'<<t[x].val<<' '<<l<<' '<<r<<endl;
        return ;
    }
    if(l==r)
    {
        t[x].val=max(vx,t[x].val)+max(vy,t[y].val);
        return ;
    }
    lzdown(x);
    lzdown(y);
    int mid=l+r>>1;
    merge(t[x].l,t[y].l,l,mid,vx,vy);
    merge(t[x].r,t[y].r,mid+1,r,max(vx,t[t[x].l].val),max(vy,t[t[y].l].val));
    update(x);
//    cout<<x<<'^'<<t[x].val<<endl;
}
LL query(int p,int l,int r)
{
    if(l==r)
    {
        return t[p].val;
    }
    lzdown(p);
    int mid=l+r>>1;
    if(t[p].r)
    {
        return query(t[p].r,mid+1,r);
    }else{
        return query(t[p].l,l,mid);
    }
}
/*
void dfs0(int u)
{
    sz[u]=1;son[u]=0;
    for(int i=h[u];i;i=e[i].nxt)
    {
        int v=e[i].v;
        if(v==fa[u])
        {
            continue;
        }
        fa[v]=u;
        dfs0(v);
        sz[u]+=sz[v];
        if(sz[v]>sz[son[u]])
        {
            son[u]=v;
        }
    }
}
*/
void dfs(int u)
{
//    cout<<u<<"b\n";
    for(int i=h[u];i;i=e[i].nxt)
    {
        int v=e[i].v;
        dfs(v);
    /*    LL mx=0;
        for(int j=1;j<=K;j++)
        {
            mx=max(mx,f[v][j]);
            f[u][j]+=mx;
        }*/
        merge(rt[u],rt[v],1,K,(LL)0,(LL)0);
    }
//    cout<<u<<"e\n";
    if(w[u]==0)
    {
        return ;
    }
    insert(rt[u],1,K,d[u],w[u]);
    cout<<u<<' '<<t[rt[u]].val<<endl;
    change(rt[u],1,K,d[u],K,val);
    cout<<u<<' '<<t[rt[u]].val<<endl;
}
int main()
{
    int x;
    scanf("%d%d%d",&n,&m,&K);
    for(int i=2;i<=n;i++)
    {
        scanf("%d",&fa[i]);
        addEdge(fa[i],i);
    }
    for(int i=1;i<=m;i++)
    {
        scanf("%d",&x);
        scanf("%d%d",&d[x],&w[x]);
    }
    dfs(1);
    printf("%lld\n",t[rt[1]].val);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3880kb

input:

10 9 10
1
1
2
2
3
1
3
8
3
5 4 1
9 4 1
6 8 1
3 1 1
4 9 1
10 1 1
2 6 1
8 7 1
7 9 1

output:

7 1
7 1
10 1
10 1
9 1
9 1
8 1
8 1
6 1
6 1
3 4
3 4
5 4
5 4
4 4
4 4
2 8
2 8
37

result:

wrong output format Extra information in the output file

Subtask #2:

score: 0
Wrong Answer

Test #10:

score: 0
Wrong Answer
time: 58ms
memory: 20524kb

input:

100000 25000 100000
1
1
2
1
2
1
5
8
8
2
5
2
2
3
1
2
11
10
18
2
9
9
9
8
1
19
18
22
20
17
20
13
30
5
9
8
13
2
19
26
14
31
23
22
2
21
8
1
22
9
50
19
49
42
47
19
21
57
9
52
41
39
10
14
60
56
34
17
18
22
53
5
34
64
29
72
33
11
9
67
58
10
58
70
57
26
65
10
15
64
67
20
26
13
51
81
11
78
40
53
70
33
34
92
7...

output:

75399 854655977
75399 854655977
98698 507682903
98698 507682903
70658 255441846
70658 255441846
50049 986603717
50049 986603717
92072 917058966
92072 917058966
68712 533421466
68712 533421466
86162 121361439
86162 121361439
97958 1038420405
97958 1038420405
96442 1038420405
96442 1038420405
65000 29...

result:

wrong answer expected '12471468294549', found '75399'

Subtask #3:

score: 0
Wrong Answer

Test #15:

score: 0
Wrong Answer
time: 0ms
memory: 3972kb

input:

1000 500 1000
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
9...

output:

1000 1
1000 1
989 1
989 1
988 1
988 1
986 2
986 2
985 3
985 3
984 3
984 3
977 3
977 3
976 3
976 3
974 3
974 3
973 3
973 3
971 3
971 3
967 3
967 3
961 3
961 3
960 3
960 3
957 3
957 3
956 3
956 3
953 3
953 3
952 3
952 3
951 3
951 3
950 3
950 3
949 3
949 3
948 3
948 3
944 3
944 3
943 3
943 3
941 3
941 ...

result:

wrong answer expected '3', found '1000'

Subtask #4:

score: 0
Wrong Answer

Test #21:

score: 0
Wrong Answer
time: 83ms
memory: 9940kb

input:

100000 90000 2
1
1
3
2
1
2
1
5
1
8
11
9
1
8
12
7
1
2
7
6
12
9
16
18
13
10
23
27
26
17
23
10
24
11
21
13
30
1
11
6
13
8
30
15
17
34
39
41
32
29
27
17
21
12
26
33
10
50
29
17
46
33
21
28
47
26
3
67
38
5
10
45
61
70
59
17
46
40
20
58
67
68
15
62
71
71
57
32
81
18
66
7
14
51
67
92
86
38
88
60
45
54
5
59...

output:

97279 225977868
97279 225977868
91077 861381197
91077 861381197
73598 941437475
73598 941437475
90111 507985037
90111 507985037
72731 507985037
72731 507985037
44975 3107978836
44975 3107978836
43745 626322854
43745 626322854
36845 1277060420
36845 1277060420
9464 880592121
9464 880592121
9441 61080...

result:

wrong answer expected '38521956905095', found '97279'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Wrong Answer

Test #31:

score: 0
Wrong Answer
time: 0ms
memory: 4892kb

input:

20000 800 60000
1
1
1
2
3
1
7
8
6
1
7
6
1
7
14
16
11
13
14
3
11
11
4
2
5
24
20
24
16
30
15
3
24
31
12
7
2
29
14
25
39
23
16
33
32
33
34
9
13
37
33
23
15
21
28
39
51
19
6
50
54
55
8
40
3
7
34
19
28
15
61
18
22
28
38
15
47
37
42
73
38
61
10
7
30
58
41
43
69
89
62
84
30
68
92
84
43
59
44
75
8
100
83
18...

output:

2779 38743287
2779 38743287
15349 589033475
15349 589033475
13606 2511107048
13606 2511107048
11678 2511107048
11678 2511107048
19162 2511107048
19162 2511107048
18029 2511107048
18029 2511107048
14975 2511107048
14975 2511107048
6403 2511107048
6403 2511107048
10422 2511107048
10422 2511107048
7323...

result:

wrong answer expected '386917987664', found '2779'

Subtask #7:

score: 0
Skipped

Dependency #3:

0%

Subtask #8:

score: 0
Skipped

Dependency #1:

0%