Submission #162822

# Submission time Handle Problem Language Result Execution time Memory
162822 2019-11-10T02:10:43 Z HungAnhGoldIBO2020 Fireworks (APIO16_fireworks) C++14
100 / 100
241 ms 53376 KB
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=3e5+2;
int par[N],c[N];
struct slopetrick{
	int a,b;
	priority_queue<int> *lis;
	slopetrick operator+(slopetrick x){
		slopetrick ans;
		ans.a = a + x.a;
		ans.b = b + x.b;
		if(x.lis->size()<lis->size()){
			ans.lis=lis;
			while(x.lis->size()){
				ans.lis->push(x.lis->top());
				x.lis->pop();
			}
		}
		else{
			ans.lis=x.lis;
			while(lis->size()){
				ans.lis->push(lis->top());
				lis->pop();
			}
		}
		return ans;
	}
} data[N];
signed main(){
//	freopen("text.txt","r",stdin);
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n,m,i,j,k,l;
	cin>>n>>m;
	for(i=2;i<=n+m;i++){
		cin>>par[i]>>c[i];
	}
	for(i=1;i<=n+m;i++){
		data[i].a=0;
		data[i].b=0;
		data[i].lis=new priority_queue<int>;
	}
	for(i=n+m;i>n;i--){
		data[i].a=1;
		data[i].b=-c[i];
		//cout<<i<<endl;
		data[i].lis->push(c[i]);
		data[i].lis->push(c[i]);
		//cout<<i<<endl;
		data[par[i]] = data[par[i]] + data[i];
	}
	for(i=n;i>1;i--){
		while(data[i].a>1){
			j=data[i].lis->top();
			data[i].lis->pop();
			data[i].a--;
			data[i].b+=j;
		}
		j=data[i].lis->top();
		data[i].lis->pop();
		k=data[i].lis->top();
		data[i].lis->pop();
		j+=c[i];
		k+=c[i];
		data[i].b-=c[i];
		data[i].lis->push(k);
		data[i].lis->push(j);
		data[par[i]] = data[par[i]] + data[i];
	}
	while(data[1].a>0){
		j=data[1].lis->top();
		data[1].lis->pop();
		data[1].a--;
		data[1].b+=j;
	}
	cout<<data[1].b;
}
/*
4 6
1 5
2 5
2 8
3 3
3 2
3 3
2 9
4 4
4 3
*/

Compilation message

fireworks.cpp: In function 'int main()':
fireworks.cpp:34:16: warning: unused variable 'l' [-Wunused-variable]
  int n,m,i,j,k,l;
                ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 508 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 296 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 380 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 420 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 380 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 504 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 3 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 380 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 508 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 296 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 380 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 420 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 504 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 380 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 632 KB Output is correct
33 Correct 4 ms 760 KB Output is correct
34 Correct 13 ms 760 KB Output is correct
35 Correct 4 ms 760 KB Output is correct
36 Correct 4 ms 888 KB Output is correct
37 Correct 5 ms 1020 KB Output is correct
38 Correct 5 ms 1016 KB Output is correct
39 Correct 5 ms 1020 KB Output is correct
40 Correct 4 ms 888 KB Output is correct
41 Correct 4 ms 888 KB Output is correct
42 Correct 4 ms 888 KB Output is correct
43 Correct 5 ms 1016 KB Output is correct
44 Correct 5 ms 1016 KB Output is correct
45 Correct 5 ms 1016 KB Output is correct
46 Correct 5 ms 1272 KB Output is correct
47 Correct 6 ms 1276 KB Output is correct
48 Correct 5 ms 1144 KB Output is correct
49 Correct 5 ms 1144 KB Output is correct
50 Correct 5 ms 1016 KB Output is correct
51 Correct 5 ms 1016 KB Output is correct
52 Correct 10 ms 1120 KB Output is correct
53 Correct 5 ms 1144 KB Output is correct
54 Correct 7 ms 1144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 508 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 296 KB Output is correct
7 Correct 2 ms 380 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 380 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 420 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 2 ms 376 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 380 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 504 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 2 ms 380 KB Output is correct
27 Correct 2 ms 376 KB Output is correct
28 Correct 2 ms 376 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 2 ms 376 KB Output is correct
31 Correct 3 ms 504 KB Output is correct
32 Correct 3 ms 632 KB Output is correct
33 Correct 4 ms 760 KB Output is correct
34 Correct 13 ms 760 KB Output is correct
35 Correct 4 ms 760 KB Output is correct
36 Correct 4 ms 888 KB Output is correct
37 Correct 5 ms 1020 KB Output is correct
38 Correct 5 ms 1016 KB Output is correct
39 Correct 5 ms 1020 KB Output is correct
40 Correct 4 ms 888 KB Output is correct
41 Correct 4 ms 888 KB Output is correct
42 Correct 4 ms 888 KB Output is correct
43 Correct 5 ms 1016 KB Output is correct
44 Correct 5 ms 1016 KB Output is correct
45 Correct 5 ms 1016 KB Output is correct
46 Correct 5 ms 1272 KB Output is correct
47 Correct 6 ms 1276 KB Output is correct
48 Correct 5 ms 1144 KB Output is correct
49 Correct 5 ms 1144 KB Output is correct
50 Correct 5 ms 1016 KB Output is correct
51 Correct 5 ms 1016 KB Output is correct
52 Correct 10 ms 1120 KB Output is correct
53 Correct 5 ms 1144 KB Output is correct
54 Correct 7 ms 1144 KB Output is correct
55 Correct 10 ms 2168 KB Output is correct
56 Correct 32 ms 7280 KB Output is correct
57 Correct 59 ms 12044 KB Output is correct
58 Correct 77 ms 15220 KB Output is correct
59 Correct 101 ms 20308 KB Output is correct
60 Correct 133 ms 24980 KB Output is correct
61 Correct 151 ms 28912 KB Output is correct
62 Correct 176 ms 31496 KB Output is correct
63 Correct 225 ms 37348 KB Output is correct
64 Correct 218 ms 39280 KB Output is correct
65 Correct 115 ms 31160 KB Output is correct
66 Correct 115 ms 31100 KB Output is correct
67 Correct 116 ms 31096 KB Output is correct
68 Correct 179 ms 37792 KB Output is correct
69 Correct 201 ms 38448 KB Output is correct
70 Correct 209 ms 38520 KB Output is correct
71 Correct 241 ms 53208 KB Output is correct
72 Correct 239 ms 53376 KB Output is correct
73 Correct 213 ms 49840 KB Output is correct
74 Correct 228 ms 50312 KB Output is correct
75 Correct 220 ms 48692 KB Output is correct
76 Correct 214 ms 48712 KB Output is correct
77 Correct 223 ms 47716 KB Output is correct
78 Correct 229 ms 47332 KB Output is correct
79 Correct 205 ms 46172 KB Output is correct