Submission #972021

# Submission time Handle Problem Language Result Execution time Memory
972021 2024-04-29T17:56:38 Z NintsiChkhaidze Stranded Far From Home (BOI22_island) C++17
100 / 100
354 ms 50156 KB
#include <bits/stdc++.h>
#define s second
#define f first
#define pb push_back
#define pii pair <int,int>
#define int long long
using namespace std;
 
const int N = 2e5 + 5;
int p[N],sz[N],ans[N];
pii b[N];
bool active[N];
vector <int> v[N],vec,cmp[N];
set <pii> st;
 
int P(int x){
	if(x==p[x]) return x;
	return p[x]=P(p[x]);
}
 
void dsu(int x,int y){
	int px=P(x),py=P(y);
	if (px==py) return;
 
	st.erase(st.find({sz[px],px})); 
	st.erase(st.find({sz[py],py}));
	
	if (cmp[px].size() < cmp[py].size()) swap(px,py);
	sz[px] += sz[py];
	for (int k: cmp[py])
		cmp[px].pb(k);
 
	cmp[py].clear();
	sz[py]=0;
	st.insert({sz[px],px});
	p[py] = px;
}
 
void go(int x){
	active[x] = 1;
	st.insert({sz[x],x});
	for (int to: v[x]){
		if (active[to]){
			if (!ans[to]){
				int pto=P(to);
				st.insert({sz[pto],pto});
			}
			dsu(x,to);
		}
	}
}
 
signed main(){
	ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
 
	int n,m;
	cin>>n>>m;	
 
	for (int i = 1; i <= n; i++){
		int a;
		cin>>a;
		sz[i] = a;
		p[i] = i;
		cmp[i].pb(i);
		b[i] = {a,i};
		vec.pb(a);
		ans[i]=1;
	}
	sort(vec.begin(),vec.end());
	vec.erase(unique(vec.begin(),vec.end()),vec.end());
 
	sort(b+1,b+n+1);
	for (int i=1;i<=m;i++){
		int a,bb;
		cin>>a>>bb;
		v[a].pb(bb);
		v[bb].pb(a);
	}
 
	int l = 1;
	for (int i=0;i<vec.size();i++){

		while (l <= n && b[l].f == vec[i]){
			go(b[l].s);
			++l;
		}
 
		if (i + 1 < vec.size()){
			int nxt = vec[i + 1];
			while (st.size() && (st.begin()->f) < nxt){
				int vert = st.begin()->s;
				for (int y: cmp[vert])
					ans[y]=0;
				cmp[vert].clear();
				
				st.erase(st.begin());
				st.insert({});
			}
		}
	}
 
	for (int i=1;i<=n;i++)
		cout<<ans[i];
}	

Compilation message

island.cpp: In function 'int main()':
island.cpp:81:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   81 |  for (int i=0;i<vec.size();i++){
      |               ~^~~~~~~~~~~
island.cpp:88:13: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   88 |   if (i + 1 < vec.size()){
      |       ~~~~~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 4 ms 14940 KB Output is correct
3 Correct 4 ms 14988 KB Output is correct
4 Correct 5 ms 15000 KB Output is correct
5 Correct 4 ms 15192 KB Output is correct
6 Correct 4 ms 15196 KB Output is correct
7 Correct 4 ms 15196 KB Output is correct
8 Correct 4 ms 14940 KB Output is correct
9 Correct 3 ms 15196 KB Output is correct
10 Correct 5 ms 15196 KB Output is correct
11 Correct 5 ms 15196 KB Output is correct
12 Correct 4 ms 15196 KB Output is correct
13 Correct 5 ms 14940 KB Output is correct
14 Correct 5 ms 15196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 3 ms 14936 KB Output is correct
3 Correct 144 ms 40644 KB Output is correct
4 Correct 140 ms 38888 KB Output is correct
5 Correct 242 ms 44184 KB Output is correct
6 Correct 293 ms 45508 KB Output is correct
7 Correct 216 ms 45352 KB Output is correct
8 Correct 162 ms 40300 KB Output is correct
9 Correct 197 ms 48452 KB Output is correct
10 Correct 112 ms 37312 KB Output is correct
11 Correct 121 ms 40128 KB Output is correct
12 Correct 203 ms 39720 KB Output is correct
13 Correct 142 ms 37744 KB Output is correct
14 Correct 113 ms 38132 KB Output is correct
15 Correct 111 ms 39360 KB Output is correct
16 Correct 90 ms 38592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14940 KB Output is correct
2 Correct 326 ms 45724 KB Output is correct
3 Correct 342 ms 46048 KB Output is correct
4 Correct 136 ms 39412 KB Output is correct
5 Correct 112 ms 37820 KB Output is correct
6 Correct 293 ms 45504 KB Output is correct
7 Correct 168 ms 39356 KB Output is correct
8 Correct 148 ms 39380 KB Output is correct
9 Correct 92 ms 38452 KB Output is correct
10 Correct 126 ms 37724 KB Output is correct
11 Correct 218 ms 40544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 320 ms 42432 KB Output is correct
3 Correct 331 ms 43392 KB Output is correct
4 Correct 321 ms 45512 KB Output is correct
5 Correct 312 ms 49540 KB Output is correct
6 Correct 326 ms 45220 KB Output is correct
7 Correct 162 ms 46352 KB Output is correct
8 Correct 103 ms 39704 KB Output is correct
9 Correct 108 ms 31052 KB Output is correct
10 Correct 354 ms 49592 KB Output is correct
11 Correct 208 ms 40124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 14936 KB Output is correct
2 Correct 4 ms 14940 KB Output is correct
3 Correct 4 ms 14988 KB Output is correct
4 Correct 5 ms 15000 KB Output is correct
5 Correct 4 ms 15192 KB Output is correct
6 Correct 4 ms 15196 KB Output is correct
7 Correct 4 ms 15196 KB Output is correct
8 Correct 4 ms 14940 KB Output is correct
9 Correct 3 ms 15196 KB Output is correct
10 Correct 5 ms 15196 KB Output is correct
11 Correct 5 ms 15196 KB Output is correct
12 Correct 4 ms 15196 KB Output is correct
13 Correct 5 ms 14940 KB Output is correct
14 Correct 5 ms 15196 KB Output is correct
15 Correct 3 ms 14936 KB Output is correct
16 Correct 3 ms 14936 KB Output is correct
17 Correct 144 ms 40644 KB Output is correct
18 Correct 140 ms 38888 KB Output is correct
19 Correct 242 ms 44184 KB Output is correct
20 Correct 293 ms 45508 KB Output is correct
21 Correct 216 ms 45352 KB Output is correct
22 Correct 162 ms 40300 KB Output is correct
23 Correct 197 ms 48452 KB Output is correct
24 Correct 112 ms 37312 KB Output is correct
25 Correct 121 ms 40128 KB Output is correct
26 Correct 203 ms 39720 KB Output is correct
27 Correct 142 ms 37744 KB Output is correct
28 Correct 113 ms 38132 KB Output is correct
29 Correct 111 ms 39360 KB Output is correct
30 Correct 90 ms 38592 KB Output is correct
31 Correct 3 ms 14940 KB Output is correct
32 Correct 326 ms 45724 KB Output is correct
33 Correct 342 ms 46048 KB Output is correct
34 Correct 136 ms 39412 KB Output is correct
35 Correct 112 ms 37820 KB Output is correct
36 Correct 293 ms 45504 KB Output is correct
37 Correct 168 ms 39356 KB Output is correct
38 Correct 148 ms 39380 KB Output is correct
39 Correct 92 ms 38452 KB Output is correct
40 Correct 126 ms 37724 KB Output is correct
41 Correct 218 ms 40544 KB Output is correct
42 Correct 3 ms 14936 KB Output is correct
43 Correct 320 ms 42432 KB Output is correct
44 Correct 331 ms 43392 KB Output is correct
45 Correct 321 ms 45512 KB Output is correct
46 Correct 312 ms 49540 KB Output is correct
47 Correct 326 ms 45220 KB Output is correct
48 Correct 162 ms 46352 KB Output is correct
49 Correct 103 ms 39704 KB Output is correct
50 Correct 108 ms 31052 KB Output is correct
51 Correct 354 ms 49592 KB Output is correct
52 Correct 208 ms 40124 KB Output is correct
53 Correct 3 ms 14940 KB Output is correct
54 Correct 3 ms 14940 KB Output is correct
55 Correct 3 ms 14940 KB Output is correct
56 Correct 5 ms 15196 KB Output is correct
57 Correct 4 ms 15196 KB Output is correct
58 Correct 5 ms 15044 KB Output is correct
59 Correct 5 ms 15196 KB Output is correct
60 Correct 4 ms 14940 KB Output is correct
61 Correct 4 ms 15196 KB Output is correct
62 Correct 5 ms 15196 KB Output is correct
63 Correct 4 ms 15196 KB Output is correct
64 Correct 4 ms 15212 KB Output is correct
65 Correct 4 ms 15192 KB Output is correct
66 Correct 5 ms 15196 KB Output is correct
67 Correct 133 ms 40684 KB Output is correct
68 Correct 117 ms 39012 KB Output is correct
69 Correct 243 ms 44152 KB Output is correct
70 Correct 218 ms 45452 KB Output is correct
71 Correct 216 ms 45500 KB Output is correct
72 Correct 136 ms 40304 KB Output is correct
73 Correct 204 ms 48572 KB Output is correct
74 Correct 112 ms 37312 KB Output is correct
75 Correct 128 ms 39872 KB Output is correct
76 Correct 212 ms 40100 KB Output is correct
77 Correct 117 ms 37820 KB Output is correct
78 Correct 113 ms 38072 KB Output is correct
79 Correct 113 ms 39400 KB Output is correct
80 Correct 101 ms 38452 KB Output is correct
81 Correct 302 ms 45724 KB Output is correct
82 Correct 306 ms 46012 KB Output is correct
83 Correct 139 ms 39388 KB Output is correct
84 Correct 151 ms 37812 KB Output is correct
85 Correct 308 ms 45756 KB Output is correct
86 Correct 152 ms 39356 KB Output is correct
87 Correct 155 ms 39376 KB Output is correct
88 Correct 133 ms 37600 KB Output is correct
89 Correct 222 ms 40164 KB Output is correct
90 Correct 319 ms 42428 KB Output is correct
91 Correct 317 ms 43216 KB Output is correct
92 Correct 320 ms 45396 KB Output is correct
93 Correct 315 ms 49280 KB Output is correct
94 Correct 260 ms 45196 KB Output is correct
95 Correct 202 ms 46496 KB Output is correct
96 Correct 94 ms 39632 KB Output is correct
97 Correct 117 ms 31168 KB Output is correct
98 Correct 284 ms 50156 KB Output is correct
99 Correct 230 ms 40532 KB Output is correct
100 Correct 34 ms 21448 KB Output is correct
101 Correct 326 ms 43392 KB Output is correct
102 Correct 229 ms 40528 KB Output is correct
103 Correct 258 ms 37892 KB Output is correct
104 Correct 327 ms 41408 KB Output is correct