#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
//long R,n,m,p,totalsum = 0;
#define limit 200001
#define MAXN limit
#define Nmax limit
#define K 18
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define ss(s) scanf("%s",s)
#define pi(x) prlongf("%d\n",x)
#define pl(x) prlongf("%lld\n",x)
#define ps(s) prlongf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef vector<long> vi;
long mpow(long base, long exp);
void ipgraph(long m);
void dfs(long u, long par);
const long mod = 1000000007;
struct wavelet_tree{
long lo, hi;
wavelet_tree *l, *r;
vi b;
//nos are in range [x,y]
//array indices are [from, to)
wavelet_tree(long *from, long *to, long x, long y){
lo = x, hi = y;
if(lo == hi or from >= to) return;
long mid = (lo+hi)/2;
auto f = [mid](long x){
return x <= mid;
};
b.reserve(to-from+1);
b.pb(0);
for(auto it = from; it != to; it++)
b.pb(b.back() + f(*it));
//see how lambda function is used here
auto pivot = stable_partition(from, to, f);
l = new wavelet_tree(from, pivot, lo, mid);
r = new wavelet_tree(pivot, to, mid+1, hi);
}
//kth smallest element in [l, r]
long kth(long l, long r, long k){
if(l > r) return 0;
if(lo == hi) return lo;
long inLeft = b[r] - b[l-1];
long lb = b[l-1]; //amt of nos in first (l-1) nos that go in left
long rb = b[r]; //amt of nos in first (r) nos that go in left
if(k <= inLeft) return this->l->kth(lb+1, rb , k);
return this->r->kth(l-lb, r-rb, k-inLeft);
}
//count of nos in [l, r] Less than or equal to k
long LTE(long l, long r, long k) {
if(l > r or k < lo) return 0;
if(hi <= k) return r - l + 1;
long lb = b[l-1], rb = b[r];
return this->l->LTE(lb+1, rb, k) + this->r->LTE(l-lb, r-rb, k);
}
//count of nos in [l, r] equal to k
long count(long l, long r, long k) {
if(l > r or k < lo or k > hi) return 0;
if(lo == hi) return r - l + 1;
long lb = b[l-1], rb = b[r], mid = (lo+hi)/2;
if(k <= mid) return this->l->count(lb+1, rb, k);
return this->r->count(l-lb, r-rb, k);
}
~wavelet_tree(){
delete l;
delete r;
}
};
long st[K + 1][MAXN];
long st2[K + 1][MAXN];
long lg[MAXN+1];
long initial_size[limit];
long current_size[limit];
long wtf_size[limit];
class UnionFind {
public:
vector<long> p,rank, setSize;
vector<long> inside[limit];
long numSets;
UnionFind(long N){
p.assign(N+1,0); for(long i = 0;i<=N;i++) {p[i]= i; inside[i].push_back(i);}
rank.assign(N+1,0);
setSize.assign(N+1,0);
numSets = N;
}
long findSet(long i){
return (p[i]==i) ? i : (p[i] = findSet(p[i]));
}
bool isSameSet(long i, long j){ return (findSet(p[i]) == findSet(p[j]));}
void unionSet(long i, long j){
if (isSameSet(i,j)) return;
long x = findSet(i); long y = findSet(j);
if(rank[x]>rank[y]) swap(x,y);
p[x] = y;
for(auto a: inside[x]) inside[y].push_back(a);
if(rank[x] == rank[y]) rank[y]++;
setSize[y] += setSize[x];
--numSets;
}
};
bool ss__(pair<long,long> a,pair<long,long> b){
long mina = max(initial_size[a.first],initial_size[a.second]);
long minb = max(initial_size[b.first],initial_size[b.second]);
return mina<minb;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
long N,M,B[limit],maxi = 0,maxii = 0;
long flag[limit] = {};
vector<pair<long,long>> edge;
cin>>N>>M;
for(long i = 1;i<=N;i++){
cin>>initial_size[i];
current_size[i] = initial_size[i];
wtf_size[i] = initial_size[i];
if(current_size[i]>maxi){
maxi = current_size[i];
maxii = i;
}
}
for(long i = 1;i<=M;i++){
long temp1, temp2;
cin>>temp1>>temp2;
if (initial_size[temp1]<initial_size[temp2]) swap(temp1,temp2);
edge.push_back(make_pair(temp1,temp2));
}
sort(edge.begin(),edge.end(),ss__);
UnionFind UF(N);
UnionFind UFDelta(N);
for(auto iter:edge){
long bigger = iter.first;
long smaller = iter.second;
long c = initial_size[bigger];
bigger = UF.findSet(bigger);
smaller = UF.findSet(smaller);
long a = current_size[bigger];
long b = current_size[smaller];
if(bigger==smaller) continue;
if(current_size[smaller] >= c) {
//cout<<smaller<<" "<<bigger<<" "<<current_size[smaller]<<endl;
UF.unionSet(smaller,bigger);
UFDelta.unionSet(smaller,bigger);
bigger = UF.findSet(bigger);
current_size[bigger] = a+b;
}
else{
for (auto i:UF.inside[smaller]){
flag[i]=1;
}
UF.unionSet(smaller,bigger);
UFDelta.unionSet(smaller,bigger);
bigger = UF.findSet(bigger);
current_size[bigger] = a+b;
}
}
for(long i = 1;i<=N;i++){
if(!flag[i]) cout<<"1"; else cout<<"0";
}
}
Compilation message
island.cpp: In function 'int main()':
island.cpp:146:11: warning: unused variable 'B' [-Wunused-variable]
146 | long N,M,B[limit],maxi = 0,maxii = 0;
| ^
island.cpp:146:29: warning: variable 'maxii' set but not used [-Wunused-but-set-variable]
146 | long N,M,B[limit],maxi = 0,maxii = 0;
| ^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
11220 KB |
Output is correct |
2 |
Correct |
7 ms |
11220 KB |
Output is correct |
3 |
Correct |
7 ms |
11296 KB |
Output is correct |
4 |
Correct |
9 ms |
11604 KB |
Output is correct |
5 |
Correct |
8 ms |
11672 KB |
Output is correct |
6 |
Correct |
8 ms |
11528 KB |
Output is correct |
7 |
Correct |
9 ms |
11604 KB |
Output is correct |
8 |
Correct |
8 ms |
11476 KB |
Output is correct |
9 |
Correct |
8 ms |
11672 KB |
Output is correct |
10 |
Correct |
8 ms |
11732 KB |
Output is correct |
11 |
Correct |
9 ms |
11792 KB |
Output is correct |
12 |
Correct |
8 ms |
11860 KB |
Output is correct |
13 |
Correct |
8 ms |
11860 KB |
Output is correct |
14 |
Correct |
8 ms |
11732 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
11220 KB |
Output is correct |
2 |
Correct |
7 ms |
11220 KB |
Output is correct |
3 |
Correct |
173 ms |
48572 KB |
Output is correct |
4 |
Correct |
276 ms |
72252 KB |
Output is correct |
5 |
Correct |
270 ms |
64412 KB |
Output is correct |
6 |
Correct |
238 ms |
66624 KB |
Output is correct |
7 |
Correct |
240 ms |
66704 KB |
Output is correct |
8 |
Correct |
322 ms |
64028 KB |
Output is correct |
9 |
Correct |
176 ms |
79612 KB |
Output is correct |
10 |
Correct |
192 ms |
46112 KB |
Output is correct |
11 |
Correct |
173 ms |
49604 KB |
Output is correct |
12 |
Correct |
260 ms |
66960 KB |
Output is correct |
13 |
Correct |
275 ms |
74404 KB |
Output is correct |
14 |
Correct |
296 ms |
71256 KB |
Output is correct |
15 |
Correct |
131 ms |
47620 KB |
Output is correct |
16 |
Correct |
95 ms |
45776 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
11220 KB |
Output is correct |
2 |
Correct |
272 ms |
75012 KB |
Output is correct |
3 |
Correct |
272 ms |
74392 KB |
Output is correct |
4 |
Correct |
287 ms |
75512 KB |
Output is correct |
5 |
Correct |
304 ms |
75116 KB |
Output is correct |
6 |
Correct |
270 ms |
74212 KB |
Output is correct |
7 |
Correct |
131 ms |
46136 KB |
Output is correct |
8 |
Correct |
141 ms |
46132 KB |
Output is correct |
9 |
Correct |
97 ms |
46004 KB |
Output is correct |
10 |
Correct |
324 ms |
76336 KB |
Output is correct |
11 |
Correct |
307 ms |
72592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
11220 KB |
Output is correct |
2 |
Correct |
283 ms |
56856 KB |
Output is correct |
3 |
Correct |
282 ms |
61056 KB |
Output is correct |
4 |
Correct |
284 ms |
64928 KB |
Output is correct |
5 |
Correct |
276 ms |
61208 KB |
Output is correct |
6 |
Correct |
251 ms |
53820 KB |
Output is correct |
7 |
Correct |
157 ms |
46100 KB |
Output is correct |
8 |
Correct |
132 ms |
55088 KB |
Output is correct |
9 |
Correct |
112 ms |
33160 KB |
Output is correct |
10 |
Correct |
283 ms |
64624 KB |
Output is correct |
11 |
Correct |
308 ms |
71056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
11220 KB |
Output is correct |
2 |
Correct |
7 ms |
11220 KB |
Output is correct |
3 |
Correct |
7 ms |
11296 KB |
Output is correct |
4 |
Correct |
9 ms |
11604 KB |
Output is correct |
5 |
Correct |
8 ms |
11672 KB |
Output is correct |
6 |
Correct |
8 ms |
11528 KB |
Output is correct |
7 |
Correct |
9 ms |
11604 KB |
Output is correct |
8 |
Correct |
8 ms |
11476 KB |
Output is correct |
9 |
Correct |
8 ms |
11672 KB |
Output is correct |
10 |
Correct |
8 ms |
11732 KB |
Output is correct |
11 |
Correct |
9 ms |
11792 KB |
Output is correct |
12 |
Correct |
8 ms |
11860 KB |
Output is correct |
13 |
Correct |
8 ms |
11860 KB |
Output is correct |
14 |
Correct |
8 ms |
11732 KB |
Output is correct |
15 |
Correct |
7 ms |
11220 KB |
Output is correct |
16 |
Correct |
7 ms |
11220 KB |
Output is correct |
17 |
Correct |
173 ms |
48572 KB |
Output is correct |
18 |
Correct |
276 ms |
72252 KB |
Output is correct |
19 |
Correct |
270 ms |
64412 KB |
Output is correct |
20 |
Correct |
238 ms |
66624 KB |
Output is correct |
21 |
Correct |
240 ms |
66704 KB |
Output is correct |
22 |
Correct |
322 ms |
64028 KB |
Output is correct |
23 |
Correct |
176 ms |
79612 KB |
Output is correct |
24 |
Correct |
192 ms |
46112 KB |
Output is correct |
25 |
Correct |
173 ms |
49604 KB |
Output is correct |
26 |
Correct |
260 ms |
66960 KB |
Output is correct |
27 |
Correct |
275 ms |
74404 KB |
Output is correct |
28 |
Correct |
296 ms |
71256 KB |
Output is correct |
29 |
Correct |
131 ms |
47620 KB |
Output is correct |
30 |
Correct |
95 ms |
45776 KB |
Output is correct |
31 |
Correct |
7 ms |
11220 KB |
Output is correct |
32 |
Correct |
272 ms |
75012 KB |
Output is correct |
33 |
Correct |
272 ms |
74392 KB |
Output is correct |
34 |
Correct |
287 ms |
75512 KB |
Output is correct |
35 |
Correct |
304 ms |
75116 KB |
Output is correct |
36 |
Correct |
270 ms |
74212 KB |
Output is correct |
37 |
Correct |
131 ms |
46136 KB |
Output is correct |
38 |
Correct |
141 ms |
46132 KB |
Output is correct |
39 |
Correct |
97 ms |
46004 KB |
Output is correct |
40 |
Correct |
324 ms |
76336 KB |
Output is correct |
41 |
Correct |
307 ms |
72592 KB |
Output is correct |
42 |
Correct |
6 ms |
11220 KB |
Output is correct |
43 |
Correct |
283 ms |
56856 KB |
Output is correct |
44 |
Correct |
282 ms |
61056 KB |
Output is correct |
45 |
Correct |
284 ms |
64928 KB |
Output is correct |
46 |
Correct |
276 ms |
61208 KB |
Output is correct |
47 |
Correct |
251 ms |
53820 KB |
Output is correct |
48 |
Correct |
157 ms |
46100 KB |
Output is correct |
49 |
Correct |
132 ms |
55088 KB |
Output is correct |
50 |
Correct |
112 ms |
33160 KB |
Output is correct |
51 |
Correct |
283 ms |
64624 KB |
Output is correct |
52 |
Correct |
308 ms |
71056 KB |
Output is correct |
53 |
Correct |
7 ms |
11220 KB |
Output is correct |
54 |
Correct |
6 ms |
11220 KB |
Output is correct |
55 |
Correct |
7 ms |
11220 KB |
Output is correct |
56 |
Correct |
9 ms |
11600 KB |
Output is correct |
57 |
Correct |
8 ms |
11604 KB |
Output is correct |
58 |
Correct |
9 ms |
11584 KB |
Output is correct |
59 |
Correct |
8 ms |
11604 KB |
Output is correct |
60 |
Correct |
8 ms |
11476 KB |
Output is correct |
61 |
Correct |
8 ms |
11604 KB |
Output is correct |
62 |
Correct |
9 ms |
11736 KB |
Output is correct |
63 |
Correct |
10 ms |
11732 KB |
Output is correct |
64 |
Correct |
8 ms |
11732 KB |
Output is correct |
65 |
Correct |
9 ms |
11860 KB |
Output is correct |
66 |
Correct |
8 ms |
11672 KB |
Output is correct |
67 |
Correct |
168 ms |
48476 KB |
Output is correct |
68 |
Correct |
310 ms |
72264 KB |
Output is correct |
69 |
Correct |
241 ms |
64532 KB |
Output is correct |
70 |
Correct |
269 ms |
66680 KB |
Output is correct |
71 |
Correct |
267 ms |
66700 KB |
Output is correct |
72 |
Correct |
272 ms |
64044 KB |
Output is correct |
73 |
Correct |
184 ms |
79560 KB |
Output is correct |
74 |
Correct |
200 ms |
46256 KB |
Output is correct |
75 |
Correct |
161 ms |
49700 KB |
Output is correct |
76 |
Correct |
288 ms |
67000 KB |
Output is correct |
77 |
Correct |
299 ms |
74420 KB |
Output is correct |
78 |
Correct |
311 ms |
71256 KB |
Output is correct |
79 |
Correct |
144 ms |
47544 KB |
Output is correct |
80 |
Correct |
103 ms |
45884 KB |
Output is correct |
81 |
Correct |
312 ms |
75112 KB |
Output is correct |
82 |
Correct |
345 ms |
74476 KB |
Output is correct |
83 |
Correct |
322 ms |
75604 KB |
Output is correct |
84 |
Correct |
307 ms |
75120 KB |
Output is correct |
85 |
Correct |
283 ms |
74296 KB |
Output is correct |
86 |
Correct |
133 ms |
46236 KB |
Output is correct |
87 |
Correct |
128 ms |
46260 KB |
Output is correct |
88 |
Correct |
295 ms |
76356 KB |
Output is correct |
89 |
Correct |
274 ms |
72504 KB |
Output is correct |
90 |
Correct |
272 ms |
56936 KB |
Output is correct |
91 |
Correct |
277 ms |
60956 KB |
Output is correct |
92 |
Correct |
283 ms |
64824 KB |
Output is correct |
93 |
Correct |
275 ms |
61104 KB |
Output is correct |
94 |
Correct |
260 ms |
53772 KB |
Output is correct |
95 |
Correct |
151 ms |
46172 KB |
Output is correct |
96 |
Correct |
115 ms |
55092 KB |
Output is correct |
97 |
Correct |
111 ms |
33116 KB |
Output is correct |
98 |
Correct |
262 ms |
64768 KB |
Output is correct |
99 |
Correct |
283 ms |
71140 KB |
Output is correct |
100 |
Correct |
60 ms |
15564 KB |
Output is correct |
101 |
Correct |
302 ms |
63104 KB |
Output is correct |
102 |
Correct |
200 ms |
45724 KB |
Output is correct |
103 |
Correct |
237 ms |
45916 KB |
Output is correct |
104 |
Correct |
277 ms |
54480 KB |
Output is correct |