Submission #967503

# Submission time Handle Problem Language Result Execution time Memory
967503 2024-04-22T09:22:01 Z boyliguanhan Fireworks (APIO16_fireworks) C++17
100 / 100
401 ms 30204 KB
#include<bits/stdc++.h>
using namespace std;
#define N 5<<17
#define pop(X) rt[X]=merge(ch[rt[X]][0],ch[rt[X]][1])
#define int long long
int deg[N],P[N],C[N],rt[N],ch[N][2],v[N],CC;
mt19937 rng(9234623);
int merge(int a,int b){
    if(!a+!b)
        return a+b;
    if(v[a]<v[b])
        swap(a,b);
    int x=rng()%2;
    ch[a][x]=merge(ch[a][x],b);
    return a;
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    int n,m,ans=0;
    cin>>n>>m;
    for(int i=2;i<=n+m;i++)
        cin>>P[i]>>C[i],deg[P[i]]++,ans+=C[i];
    for(int i=n+m;i>1;i--){
        int l=0,r=0;
        if(deg[i]){
            while(--deg[i])
                pop(i);
        } else
            rt[i]=merge(++CC,++CC);
        v[rt[i]]+=C[i];
        v[ch[rt[i]][v[ch[rt[i]][1]]>v[ch[rt[i]][0]]||!ch[rt[i]][0]]]+=C[i];
        rt[P[i]]=merge(rt[P[i]],rt[i]);
    }
    while(deg[1]--)
        pop(1);
    while(rt[1])
        ans-=v[rt[1]],pop(1);
    cout<<ans;
}

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:29:30: warning: operation on 'CC' may be undefined [-Wsequence-point]
   29 |             rt[i]=merge(++CC,++CC);
      |                              ^~~~
fireworks.cpp:29:30: warning: operation on 'CC' may be undefined [-Wsequence-point]
fireworks.cpp:24:13: warning: unused variable 'l' [-Wunused-variable]
   24 |         int l=0,r=0;
      |             ^
fireworks.cpp:24:17: warning: unused variable 'r' [-Wunused-variable]
   24 |         int l=0,r=0;
      |                 ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8536 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 2 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8536 KB Output is correct
6 Correct 2 ms 8680 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8540 KB Output is correct
10 Correct 1 ms 8792 KB Output is correct
11 Correct 1 ms 8540 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 1 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8540 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8536 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 2 ms 8536 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8536 KB Output is correct
16 Correct 2 ms 8680 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8792 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8540 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct
26 Correct 2 ms 8540 KB Output is correct
27 Correct 2 ms 8540 KB Output is correct
28 Correct 1 ms 8540 KB Output is correct
29 Correct 1 ms 8676 KB Output is correct
30 Correct 1 ms 8540 KB Output is correct
31 Correct 2 ms 8684 KB Output is correct
32 Correct 2 ms 8540 KB Output is correct
33 Correct 2 ms 8540 KB Output is correct
34 Correct 2 ms 8540 KB Output is correct
35 Correct 2 ms 8540 KB Output is correct
36 Correct 2 ms 8540 KB Output is correct
37 Correct 3 ms 8540 KB Output is correct
38 Correct 3 ms 8540 KB Output is correct
39 Correct 2 ms 8540 KB Output is correct
40 Correct 2 ms 8540 KB Output is correct
41 Correct 2 ms 8540 KB Output is correct
42 Correct 2 ms 8540 KB Output is correct
43 Correct 3 ms 8804 KB Output is correct
44 Correct 3 ms 8796 KB Output is correct
45 Correct 3 ms 8804 KB Output is correct
46 Correct 3 ms 8800 KB Output is correct
47 Correct 5 ms 8808 KB Output is correct
48 Correct 4 ms 8808 KB Output is correct
49 Correct 4 ms 8792 KB Output is correct
50 Correct 4 ms 8852 KB Output is correct
51 Correct 4 ms 8796 KB Output is correct
52 Correct 4 ms 8796 KB Output is correct
53 Correct 4 ms 8792 KB Output is correct
54 Correct 4 ms 8796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8540 KB Output is correct
7 Correct 1 ms 8540 KB Output is correct
8 Correct 1 ms 8540 KB Output is correct
9 Correct 1 ms 8536 KB Output is correct
10 Correct 1 ms 8540 KB Output is correct
11 Correct 2 ms 8536 KB Output is correct
12 Correct 1 ms 8540 KB Output is correct
13 Correct 2 ms 8540 KB Output is correct
14 Correct 1 ms 8540 KB Output is correct
15 Correct 1 ms 8536 KB Output is correct
16 Correct 2 ms 8680 KB Output is correct
17 Correct 1 ms 8540 KB Output is correct
18 Correct 1 ms 8540 KB Output is correct
19 Correct 1 ms 8540 KB Output is correct
20 Correct 1 ms 8792 KB Output is correct
21 Correct 1 ms 8540 KB Output is correct
22 Correct 1 ms 8540 KB Output is correct
23 Correct 1 ms 8540 KB Output is correct
24 Correct 1 ms 8540 KB Output is correct
25 Correct 1 ms 8540 KB Output is correct
26 Correct 2 ms 8540 KB Output is correct
27 Correct 2 ms 8540 KB Output is correct
28 Correct 1 ms 8540 KB Output is correct
29 Correct 1 ms 8676 KB Output is correct
30 Correct 1 ms 8540 KB Output is correct
31 Correct 2 ms 8684 KB Output is correct
32 Correct 2 ms 8540 KB Output is correct
33 Correct 2 ms 8540 KB Output is correct
34 Correct 2 ms 8540 KB Output is correct
35 Correct 2 ms 8540 KB Output is correct
36 Correct 2 ms 8540 KB Output is correct
37 Correct 3 ms 8540 KB Output is correct
38 Correct 3 ms 8540 KB Output is correct
39 Correct 2 ms 8540 KB Output is correct
40 Correct 2 ms 8540 KB Output is correct
41 Correct 2 ms 8540 KB Output is correct
42 Correct 2 ms 8540 KB Output is correct
43 Correct 3 ms 8804 KB Output is correct
44 Correct 3 ms 8796 KB Output is correct
45 Correct 3 ms 8804 KB Output is correct
46 Correct 3 ms 8800 KB Output is correct
47 Correct 5 ms 8808 KB Output is correct
48 Correct 4 ms 8808 KB Output is correct
49 Correct 4 ms 8792 KB Output is correct
50 Correct 4 ms 8852 KB Output is correct
51 Correct 4 ms 8796 KB Output is correct
52 Correct 4 ms 8796 KB Output is correct
53 Correct 4 ms 8792 KB Output is correct
54 Correct 4 ms 8796 KB Output is correct
55 Correct 4 ms 8792 KB Output is correct
56 Correct 15 ms 13404 KB Output is correct
57 Correct 26 ms 14244 KB Output is correct
58 Correct 34 ms 14684 KB Output is correct
59 Correct 48 ms 15236 KB Output is correct
60 Correct 57 ms 18912 KB Output is correct
61 Correct 65 ms 19520 KB Output is correct
62 Correct 73 ms 19900 KB Output is correct
63 Correct 88 ms 20616 KB Output is correct
64 Correct 103 ms 20884 KB Output is correct
65 Correct 43 ms 19940 KB Output is correct
66 Correct 45 ms 20052 KB Output is correct
67 Correct 44 ms 20052 KB Output is correct
68 Correct 111 ms 25056 KB Output is correct
69 Correct 115 ms 25168 KB Output is correct
70 Correct 117 ms 25168 KB Output is correct
71 Correct 254 ms 29892 KB Output is correct
72 Correct 224 ms 29976 KB Output is correct
73 Correct 240 ms 30036 KB Output is correct
74 Correct 245 ms 29908 KB Output is correct
75 Correct 271 ms 30012 KB Output is correct
76 Correct 261 ms 30048 KB Output is correct
77 Correct 268 ms 29684 KB Output is correct
78 Correct 286 ms 29524 KB Output is correct
79 Correct 401 ms 30204 KB Output is correct