#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5+1;
int n, m, a[N], p[N], sz[N], dp[N];
vector<int> adj[N];
pair<int, int> s[N];
set<pair<int, int>> st[N];
bitset<N> ok;
int findSet(int x) {
return p[x] = (p[x] == x ? x : findSet(p[x]));
}
void unite(int x, int y) {
int X = x;
x = findSet(x);
y = findSet(y);
if (x == y) return;
if (st[x].size() < st[y].size()) {
swap(x, y);
}
p[y] = x;
sz[x] += sz[y];
for (pair<int, int> z : st[y]) {
st[x].insert(z);
}
while (*st[x].begin() <= make_pair(a[X], X)) st[x].erase(st[x].begin());
}
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
cin >> n >> m;
a[n] = INT_MAX;
for (int i = 0; i < n; i++) {
cin >> a[i];
s[i] = make_pair(a[i], i);
}
sort(s, s+n);
for (int i = 0; i < m; i++) {
int x, y;
cin >> x >> y;
x--; y--;
adj[x].push_back(y);
adj[y].push_back(x);
}
for (int i = 0; i < n; i++) {
p[i] = i;
sz[i] = a[i];
st[i].insert(make_pair(INT_MAX, n));
for (int& j : adj[i]) {
if (make_pair(a[j], j) > make_pair(a[i], i)) st[i].insert(make_pair(a[j], j));
}
}
for (int i = 0; i < n; i++) {
int x = s[i].second;
for (int& j : adj[x]) {
if (make_pair(a[j], j) < make_pair(a[x], x)) unite(x, j);
}
int y = findSet(x);
int z = sz[y];
int nwMn = st[y].begin()->second;
if (nwMn == n) {
dp[x] = x;
ok[x] = 1;
}
else if (a[nwMn] <= z) {
dp[x] = nwMn;
}
else {
dp[x] = x;
}
}
for (int i = n-1; i >= 0; i--) {
int x = s[i].second;
ok[x] = ok[dp[x]];
}
for (int i = 0; i < n; i++) {
cout << ok[i];
}
cout << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
6 ms |
14420 KB |
Output is correct |
3 |
Correct |
6 ms |
14420 KB |
Output is correct |
4 |
Correct |
8 ms |
14872 KB |
Output is correct |
5 |
Correct |
8 ms |
14928 KB |
Output is correct |
6 |
Correct |
8 ms |
14804 KB |
Output is correct |
7 |
Correct |
8 ms |
14804 KB |
Output is correct |
8 |
Correct |
9 ms |
14804 KB |
Output is correct |
9 |
Correct |
7 ms |
14932 KB |
Output is correct |
10 |
Correct |
9 ms |
14804 KB |
Output is correct |
11 |
Correct |
8 ms |
14804 KB |
Output is correct |
12 |
Correct |
7 ms |
14804 KB |
Output is correct |
13 |
Correct |
8 ms |
14804 KB |
Output is correct |
14 |
Correct |
8 ms |
14804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
6 ms |
14420 KB |
Output is correct |
3 |
Correct |
164 ms |
56200 KB |
Output is correct |
4 |
Correct |
175 ms |
56448 KB |
Output is correct |
5 |
Correct |
194 ms |
54956 KB |
Output is correct |
6 |
Correct |
216 ms |
56292 KB |
Output is correct |
7 |
Correct |
248 ms |
56272 KB |
Output is correct |
8 |
Correct |
240 ms |
60108 KB |
Output is correct |
9 |
Correct |
171 ms |
57544 KB |
Output is correct |
10 |
Correct |
180 ms |
56816 KB |
Output is correct |
11 |
Correct |
216 ms |
56888 KB |
Output is correct |
12 |
Correct |
224 ms |
58444 KB |
Output is correct |
13 |
Correct |
150 ms |
55272 KB |
Output is correct |
14 |
Correct |
160 ms |
55276 KB |
Output is correct |
15 |
Correct |
155 ms |
55288 KB |
Output is correct |
16 |
Correct |
102 ms |
54860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
235 ms |
55088 KB |
Output is correct |
3 |
Correct |
240 ms |
55244 KB |
Output is correct |
4 |
Correct |
155 ms |
55244 KB |
Output is correct |
5 |
Correct |
163 ms |
55356 KB |
Output is correct |
6 |
Correct |
242 ms |
55324 KB |
Output is correct |
7 |
Correct |
180 ms |
55296 KB |
Output is correct |
8 |
Correct |
192 ms |
55308 KB |
Output is correct |
9 |
Correct |
113 ms |
54912 KB |
Output is correct |
10 |
Correct |
167 ms |
56016 KB |
Output is correct |
11 |
Correct |
204 ms |
55484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
302 ms |
56344 KB |
Output is correct |
3 |
Correct |
287 ms |
56268 KB |
Output is correct |
4 |
Correct |
297 ms |
56480 KB |
Output is correct |
5 |
Correct |
256 ms |
56260 KB |
Output is correct |
6 |
Correct |
244 ms |
56660 KB |
Output is correct |
7 |
Correct |
189 ms |
56896 KB |
Output is correct |
8 |
Correct |
154 ms |
63052 KB |
Output is correct |
9 |
Correct |
203 ms |
47652 KB |
Output is correct |
10 |
Correct |
237 ms |
56424 KB |
Output is correct |
11 |
Correct |
188 ms |
55500 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
14420 KB |
Output is correct |
2 |
Correct |
6 ms |
14420 KB |
Output is correct |
3 |
Correct |
6 ms |
14420 KB |
Output is correct |
4 |
Correct |
8 ms |
14872 KB |
Output is correct |
5 |
Correct |
8 ms |
14928 KB |
Output is correct |
6 |
Correct |
8 ms |
14804 KB |
Output is correct |
7 |
Correct |
8 ms |
14804 KB |
Output is correct |
8 |
Correct |
9 ms |
14804 KB |
Output is correct |
9 |
Correct |
7 ms |
14932 KB |
Output is correct |
10 |
Correct |
9 ms |
14804 KB |
Output is correct |
11 |
Correct |
8 ms |
14804 KB |
Output is correct |
12 |
Correct |
7 ms |
14804 KB |
Output is correct |
13 |
Correct |
8 ms |
14804 KB |
Output is correct |
14 |
Correct |
8 ms |
14804 KB |
Output is correct |
15 |
Correct |
7 ms |
14420 KB |
Output is correct |
16 |
Correct |
6 ms |
14420 KB |
Output is correct |
17 |
Correct |
164 ms |
56200 KB |
Output is correct |
18 |
Correct |
175 ms |
56448 KB |
Output is correct |
19 |
Correct |
194 ms |
54956 KB |
Output is correct |
20 |
Correct |
216 ms |
56292 KB |
Output is correct |
21 |
Correct |
248 ms |
56272 KB |
Output is correct |
22 |
Correct |
240 ms |
60108 KB |
Output is correct |
23 |
Correct |
171 ms |
57544 KB |
Output is correct |
24 |
Correct |
180 ms |
56816 KB |
Output is correct |
25 |
Correct |
216 ms |
56888 KB |
Output is correct |
26 |
Correct |
224 ms |
58444 KB |
Output is correct |
27 |
Correct |
150 ms |
55272 KB |
Output is correct |
28 |
Correct |
160 ms |
55276 KB |
Output is correct |
29 |
Correct |
155 ms |
55288 KB |
Output is correct |
30 |
Correct |
102 ms |
54860 KB |
Output is correct |
31 |
Correct |
7 ms |
14420 KB |
Output is correct |
32 |
Correct |
235 ms |
55088 KB |
Output is correct |
33 |
Correct |
240 ms |
55244 KB |
Output is correct |
34 |
Correct |
155 ms |
55244 KB |
Output is correct |
35 |
Correct |
163 ms |
55356 KB |
Output is correct |
36 |
Correct |
242 ms |
55324 KB |
Output is correct |
37 |
Correct |
180 ms |
55296 KB |
Output is correct |
38 |
Correct |
192 ms |
55308 KB |
Output is correct |
39 |
Correct |
113 ms |
54912 KB |
Output is correct |
40 |
Correct |
167 ms |
56016 KB |
Output is correct |
41 |
Correct |
204 ms |
55484 KB |
Output is correct |
42 |
Correct |
7 ms |
14420 KB |
Output is correct |
43 |
Correct |
302 ms |
56344 KB |
Output is correct |
44 |
Correct |
287 ms |
56268 KB |
Output is correct |
45 |
Correct |
297 ms |
56480 KB |
Output is correct |
46 |
Correct |
256 ms |
56260 KB |
Output is correct |
47 |
Correct |
244 ms |
56660 KB |
Output is correct |
48 |
Correct |
189 ms |
56896 KB |
Output is correct |
49 |
Correct |
154 ms |
63052 KB |
Output is correct |
50 |
Correct |
203 ms |
47652 KB |
Output is correct |
51 |
Correct |
237 ms |
56424 KB |
Output is correct |
52 |
Correct |
188 ms |
55500 KB |
Output is correct |
53 |
Correct |
9 ms |
14420 KB |
Output is correct |
54 |
Correct |
7 ms |
14420 KB |
Output is correct |
55 |
Correct |
7 ms |
14420 KB |
Output is correct |
56 |
Correct |
8 ms |
14804 KB |
Output is correct |
57 |
Correct |
8 ms |
14804 KB |
Output is correct |
58 |
Correct |
9 ms |
14804 KB |
Output is correct |
59 |
Correct |
9 ms |
14804 KB |
Output is correct |
60 |
Correct |
8 ms |
14804 KB |
Output is correct |
61 |
Correct |
8 ms |
14932 KB |
Output is correct |
62 |
Correct |
8 ms |
14804 KB |
Output is correct |
63 |
Correct |
9 ms |
14804 KB |
Output is correct |
64 |
Correct |
8 ms |
14804 KB |
Output is correct |
65 |
Correct |
8 ms |
14804 KB |
Output is correct |
66 |
Correct |
9 ms |
14804 KB |
Output is correct |
67 |
Correct |
152 ms |
56208 KB |
Output is correct |
68 |
Correct |
161 ms |
56508 KB |
Output is correct |
69 |
Correct |
184 ms |
54916 KB |
Output is correct |
70 |
Correct |
196 ms |
56160 KB |
Output is correct |
71 |
Correct |
210 ms |
56252 KB |
Output is correct |
72 |
Correct |
252 ms |
60228 KB |
Output is correct |
73 |
Correct |
155 ms |
57528 KB |
Output is correct |
74 |
Correct |
183 ms |
56812 KB |
Output is correct |
75 |
Correct |
225 ms |
56812 KB |
Output is correct |
76 |
Correct |
227 ms |
58560 KB |
Output is correct |
77 |
Correct |
148 ms |
55220 KB |
Output is correct |
78 |
Correct |
152 ms |
55356 KB |
Output is correct |
79 |
Correct |
152 ms |
55324 KB |
Output is correct |
80 |
Correct |
127 ms |
54860 KB |
Output is correct |
81 |
Correct |
254 ms |
54988 KB |
Output is correct |
82 |
Correct |
253 ms |
55244 KB |
Output is correct |
83 |
Correct |
152 ms |
55320 KB |
Output is correct |
84 |
Correct |
154 ms |
55244 KB |
Output is correct |
85 |
Correct |
235 ms |
55248 KB |
Output is correct |
86 |
Correct |
189 ms |
55280 KB |
Output is correct |
87 |
Correct |
168 ms |
55244 KB |
Output is correct |
88 |
Correct |
155 ms |
55880 KB |
Output is correct |
89 |
Correct |
189 ms |
55484 KB |
Output is correct |
90 |
Correct |
359 ms |
56408 KB |
Output is correct |
91 |
Correct |
289 ms |
56232 KB |
Output is correct |
92 |
Correct |
316 ms |
56480 KB |
Output is correct |
93 |
Correct |
243 ms |
56304 KB |
Output is correct |
94 |
Correct |
285 ms |
56756 KB |
Output is correct |
95 |
Correct |
185 ms |
56888 KB |
Output is correct |
96 |
Correct |
159 ms |
63052 KB |
Output is correct |
97 |
Correct |
198 ms |
47568 KB |
Output is correct |
98 |
Correct |
226 ms |
56496 KB |
Output is correct |
99 |
Correct |
238 ms |
55404 KB |
Output is correct |
100 |
Correct |
98 ms |
31956 KB |
Output is correct |
101 |
Correct |
299 ms |
56436 KB |
Output is correct |
102 |
Correct |
242 ms |
57460 KB |
Output is correct |
103 |
Correct |
331 ms |
57900 KB |
Output is correct |
104 |
Correct |
330 ms |
57068 KB |
Output is correct |