#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
#define int long long
#define sqrt sqrtl
using namespace std;
const long long oo = 1000000000000000000;
long long sum, ans = 0, mx = 0, mn = 1000000000, num, pos;
/*
ViHHiPuh
(( `'-""``""-'` ))
)-__-_.._-__-(
/ --- (o _ o) --- \
\ .-* ( .0. ) *-. /
_'-. ,_ '=' _, .-'_
/ `;#'#'# - #'#'#;` \
\_)) -----'#'----- ((_/
# --------- #
'# ------- ------ #'
/..-'# ------- #'-.\
_\...-\'# -- #'/-.../_
((____)- '#' -(____))
cout << fixed << setprecision(6) << x;
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
freopen ( "sum.in", "r", stdin )
*/
int n, m, a[ 200001 ], x, y, p[ 200001 ], r[ 200001 ], c[ 200001 ];
int an[ 200001 ];
vector <int> v[ 200001 ], v1;
vector <pair<int, pair<int, int> > > vv;
map <int, vector <int> > mp;
set <int> s[ 200001 ];
set <int> st, stt;
int used[ 200001 ];
pair<int, int> fin( int a, int ans ) {
if ( p[ a ] == a )
return { a, an[ a ] };
pair<int, int> pp = fin( p[ a ], 1 );
ans = an[ a ] & pp.second;
p[ a ] = pp.first;
an[ a ] = ans;
return { p[ a ], ans };
}
void unin( int a, int b ) {
a = fin( a, an[ a ] ).first;
b = fin( b, an[ b ] ).first;
if ( a == b )
return;
if ( ::a[ a ] < ::a[ b ] )
swap( a, b );
if ( r[ a ] < r[ b ] && ::a[ a ] <= ::a[ b ] )
swap( a, b );
r[ a ] += r[ b ];
c[ a ] += c[ b ];
p[ b ] = a;
}
main () {
cin >> n >> m;
for ( int i = 1; i <= n; i ++ ) {
cin >> a[ i ];
an[ i ] = 1;
p[ i ] = i;
r[ i ] = 1;
c[ i ] = a[ i ];
mp[ a[ i ] ].push_back( i );
st.insert( a[ i ] );
}
for ( int i = 1; i <= m; i ++ ) {
cin >> x >> y;
if ( a[ x ] < a[ y ] )
swap( x, y );
vv.push_back( { a[ x ], make_pair( x, y ) } );
}
sort( vv.begin(), vv.end() );
reverse( vv.begin(), vv.end() );
stt = st;
for ( auto i : st ) {
if ( stt.size() )
stt.erase( stt.begin() );
if ( stt.size() )
ans = *stt.begin();
else
ans = 0;
while ( vv.size() && vv.back().first <= i ) {
num = fin( vv.back().second.second, an[ vv.back().second.second ] ).first;
if ( c[ num ] < vv.back().first ) {
an[ num ] = 0;
}
v[ vv.back().second.first ].push_back( vv.back().second.second );
v[ vv.back().second.second ].push_back( vv.back().second.first );
unin( vv.back().second.first, vv.back().second.second );
vv.pop_back();
}
}
for ( int i = 1; i <= n; i ++ ) {
fin( i, an[ i ] );
cout << an[ i ];
}
}
Compilation message
island.cpp:80:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
80 | main () {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14420 KB |
Output is correct |
3 |
Correct |
8 ms |
14420 KB |
Output is correct |
4 |
Correct |
10 ms |
14912 KB |
Output is correct |
5 |
Correct |
10 ms |
14932 KB |
Output is correct |
6 |
Correct |
9 ms |
14548 KB |
Output is correct |
7 |
Correct |
11 ms |
14804 KB |
Output is correct |
8 |
Correct |
10 ms |
14736 KB |
Output is correct |
9 |
Correct |
9 ms |
14548 KB |
Output is correct |
10 |
Correct |
11 ms |
14932 KB |
Output is correct |
11 |
Correct |
13 ms |
14924 KB |
Output is correct |
12 |
Correct |
10 ms |
14932 KB |
Output is correct |
13 |
Correct |
9 ms |
14616 KB |
Output is correct |
14 |
Correct |
10 ms |
14568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14548 KB |
Output is correct |
2 |
Correct |
7 ms |
14420 KB |
Output is correct |
3 |
Correct |
368 ms |
68128 KB |
Output is correct |
4 |
Correct |
202 ms |
35720 KB |
Output is correct |
5 |
Correct |
390 ms |
66068 KB |
Output is correct |
6 |
Correct |
382 ms |
58320 KB |
Output is correct |
7 |
Correct |
414 ms |
67876 KB |
Output is correct |
8 |
Correct |
280 ms |
35912 KB |
Output is correct |
9 |
Correct |
391 ms |
60588 KB |
Output is correct |
10 |
Correct |
306 ms |
59916 KB |
Output is correct |
11 |
Correct |
206 ms |
36496 KB |
Output is correct |
12 |
Correct |
236 ms |
35908 KB |
Output is correct |
13 |
Correct |
190 ms |
34880 KB |
Output is correct |
14 |
Correct |
201 ms |
34872 KB |
Output is correct |
15 |
Correct |
368 ms |
67960 KB |
Output is correct |
16 |
Correct |
314 ms |
67368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14428 KB |
Output is correct |
2 |
Correct |
604 ms |
67812 KB |
Output is correct |
3 |
Correct |
520 ms |
60116 KB |
Output is correct |
4 |
Correct |
252 ms |
36636 KB |
Output is correct |
5 |
Correct |
194 ms |
36736 KB |
Output is correct |
6 |
Correct |
583 ms |
69804 KB |
Output is correct |
7 |
Correct |
363 ms |
69664 KB |
Output is correct |
8 |
Correct |
363 ms |
69716 KB |
Output is correct |
9 |
Correct |
329 ms |
69252 KB |
Output is correct |
10 |
Correct |
309 ms |
51676 KB |
Output is correct |
11 |
Correct |
231 ms |
38000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
14420 KB |
Output is correct |
2 |
Correct |
307 ms |
35992 KB |
Output is correct |
3 |
Correct |
324 ms |
40128 KB |
Output is correct |
4 |
Correct |
322 ms |
40632 KB |
Output is correct |
5 |
Correct |
311 ms |
40236 KB |
Output is correct |
6 |
Correct |
299 ms |
39416 KB |
Output is correct |
7 |
Correct |
241 ms |
40848 KB |
Output is correct |
8 |
Correct |
213 ms |
39720 KB |
Output is correct |
9 |
Correct |
223 ms |
32060 KB |
Output is correct |
10 |
Correct |
289 ms |
38740 KB |
Output is correct |
11 |
Correct |
229 ms |
37916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
7 ms |
14420 KB |
Output is correct |
3 |
Correct |
8 ms |
14420 KB |
Output is correct |
4 |
Correct |
10 ms |
14912 KB |
Output is correct |
5 |
Correct |
10 ms |
14932 KB |
Output is correct |
6 |
Correct |
9 ms |
14548 KB |
Output is correct |
7 |
Correct |
11 ms |
14804 KB |
Output is correct |
8 |
Correct |
10 ms |
14736 KB |
Output is correct |
9 |
Correct |
9 ms |
14548 KB |
Output is correct |
10 |
Correct |
11 ms |
14932 KB |
Output is correct |
11 |
Correct |
13 ms |
14924 KB |
Output is correct |
12 |
Correct |
10 ms |
14932 KB |
Output is correct |
13 |
Correct |
9 ms |
14616 KB |
Output is correct |
14 |
Correct |
10 ms |
14568 KB |
Output is correct |
15 |
Correct |
7 ms |
14548 KB |
Output is correct |
16 |
Correct |
7 ms |
14420 KB |
Output is correct |
17 |
Correct |
368 ms |
68128 KB |
Output is correct |
18 |
Correct |
202 ms |
35720 KB |
Output is correct |
19 |
Correct |
390 ms |
66068 KB |
Output is correct |
20 |
Correct |
382 ms |
58320 KB |
Output is correct |
21 |
Correct |
414 ms |
67876 KB |
Output is correct |
22 |
Correct |
280 ms |
35912 KB |
Output is correct |
23 |
Correct |
391 ms |
60588 KB |
Output is correct |
24 |
Correct |
306 ms |
59916 KB |
Output is correct |
25 |
Correct |
206 ms |
36496 KB |
Output is correct |
26 |
Correct |
236 ms |
35908 KB |
Output is correct |
27 |
Correct |
190 ms |
34880 KB |
Output is correct |
28 |
Correct |
201 ms |
34872 KB |
Output is correct |
29 |
Correct |
368 ms |
67960 KB |
Output is correct |
30 |
Correct |
314 ms |
67368 KB |
Output is correct |
31 |
Correct |
8 ms |
14428 KB |
Output is correct |
32 |
Correct |
604 ms |
67812 KB |
Output is correct |
33 |
Correct |
520 ms |
60116 KB |
Output is correct |
34 |
Correct |
252 ms |
36636 KB |
Output is correct |
35 |
Correct |
194 ms |
36736 KB |
Output is correct |
36 |
Correct |
583 ms |
69804 KB |
Output is correct |
37 |
Correct |
363 ms |
69664 KB |
Output is correct |
38 |
Correct |
363 ms |
69716 KB |
Output is correct |
39 |
Correct |
329 ms |
69252 KB |
Output is correct |
40 |
Correct |
309 ms |
51676 KB |
Output is correct |
41 |
Correct |
231 ms |
38000 KB |
Output is correct |
42 |
Correct |
8 ms |
14420 KB |
Output is correct |
43 |
Correct |
307 ms |
35992 KB |
Output is correct |
44 |
Correct |
324 ms |
40128 KB |
Output is correct |
45 |
Correct |
322 ms |
40632 KB |
Output is correct |
46 |
Correct |
311 ms |
40236 KB |
Output is correct |
47 |
Correct |
299 ms |
39416 KB |
Output is correct |
48 |
Correct |
241 ms |
40848 KB |
Output is correct |
49 |
Correct |
213 ms |
39720 KB |
Output is correct |
50 |
Correct |
223 ms |
32060 KB |
Output is correct |
51 |
Correct |
289 ms |
38740 KB |
Output is correct |
52 |
Correct |
229 ms |
37916 KB |
Output is correct |
53 |
Correct |
9 ms |
14368 KB |
Output is correct |
54 |
Correct |
8 ms |
14408 KB |
Output is correct |
55 |
Correct |
8 ms |
14420 KB |
Output is correct |
56 |
Correct |
10 ms |
14932 KB |
Output is correct |
57 |
Correct |
11 ms |
14932 KB |
Output is correct |
58 |
Correct |
10 ms |
14548 KB |
Output is correct |
59 |
Correct |
10 ms |
14804 KB |
Output is correct |
60 |
Correct |
12 ms |
14804 KB |
Output is correct |
61 |
Correct |
9 ms |
14676 KB |
Output is correct |
62 |
Correct |
10 ms |
14936 KB |
Output is correct |
63 |
Correct |
12 ms |
15060 KB |
Output is correct |
64 |
Correct |
13 ms |
14964 KB |
Output is correct |
65 |
Correct |
9 ms |
14676 KB |
Output is correct |
66 |
Correct |
9 ms |
14676 KB |
Output is correct |
67 |
Correct |
372 ms |
72352 KB |
Output is correct |
68 |
Correct |
200 ms |
38928 KB |
Output is correct |
69 |
Correct |
380 ms |
70320 KB |
Output is correct |
70 |
Correct |
362 ms |
62772 KB |
Output is correct |
71 |
Correct |
399 ms |
72236 KB |
Output is correct |
72 |
Correct |
307 ms |
40220 KB |
Output is correct |
73 |
Correct |
327 ms |
64928 KB |
Output is correct |
74 |
Correct |
298 ms |
63360 KB |
Output is correct |
75 |
Correct |
216 ms |
39980 KB |
Output is correct |
76 |
Correct |
236 ms |
38832 KB |
Output is correct |
77 |
Correct |
198 ms |
37828 KB |
Output is correct |
78 |
Correct |
201 ms |
38048 KB |
Output is correct |
79 |
Correct |
362 ms |
72336 KB |
Output is correct |
80 |
Correct |
326 ms |
71300 KB |
Output is correct |
81 |
Correct |
550 ms |
71928 KB |
Output is correct |
82 |
Correct |
514 ms |
62900 KB |
Output is correct |
83 |
Correct |
249 ms |
39340 KB |
Output is correct |
84 |
Correct |
199 ms |
37876 KB |
Output is correct |
85 |
Correct |
572 ms |
72296 KB |
Output is correct |
86 |
Correct |
349 ms |
72340 KB |
Output is correct |
87 |
Correct |
353 ms |
72316 KB |
Output is correct |
88 |
Correct |
308 ms |
53572 KB |
Output is correct |
89 |
Correct |
224 ms |
39212 KB |
Output is correct |
90 |
Correct |
331 ms |
40428 KB |
Output is correct |
91 |
Correct |
314 ms |
40156 KB |
Output is correct |
92 |
Correct |
323 ms |
40636 KB |
Output is correct |
93 |
Correct |
297 ms |
40192 KB |
Output is correct |
94 |
Correct |
283 ms |
39332 KB |
Output is correct |
95 |
Correct |
237 ms |
40844 KB |
Output is correct |
96 |
Correct |
197 ms |
39756 KB |
Output is correct |
97 |
Correct |
189 ms |
32176 KB |
Output is correct |
98 |
Correct |
252 ms |
38788 KB |
Output is correct |
99 |
Correct |
210 ms |
37916 KB |
Output is correct |
100 |
Correct |
137 ms |
25972 KB |
Output is correct |
101 |
Correct |
535 ms |
63028 KB |
Output is correct |
102 |
Correct |
262 ms |
37204 KB |
Output is correct |
103 |
Correct |
467 ms |
56620 KB |
Output is correct |
104 |
Correct |
592 ms |
71300 KB |
Output is correct |