#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <iomanip>
#include <array>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <list>
#include <iterator>
#include <numeric>
#include <complex>
#include <utility>
#include <random>
#include <cassert>
#include <fstream>
using namespace std;
mt19937 rnd(7069);
/* -------------------- Typedefs -------------------- */
typedef int itn;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef float fl;
typedef long double ld;
/* -------------------- Usings -------------------- */
using vi = vector<int>;
using vll = vector<ll>;
using mii = map<int, int>;
using mll = map<ll, ll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
/* -------------------- Defines -------------------- */
#define ff first
#define ss second
#define pub push_back
#define pob pop_back
#define puf push_front
#define pof pop_front
#define mpr make_pair
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
#define all(x) (x).begin(), (x).end()
#define USACO freopen("feast.in", "r", stdin); freopen("feast.out", "w", stdout);
/* -------------------- Constants -------------------- */
const int MAX = int(1e9 + 5);
const ll MAXL = ll(1e18) + 5ll;
const ll MOD = ll(998244353);
const ll MOD2 = ll(998244353);
/* -------------------- Functions -------------------- */
void fastio() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
void precision(int x) {
cout.setf(ios::fixed | ios::showpoint);
cout.precision(x);
}
ll gcd(ll a, ll b) {
if (a == 0 || b == 0) return(max(a, b));
while (b) {
a %= b;
swap(a, b);
}
return a;
}
ll lcm(ll a, ll b) {
return a / gcd(a, b) * b;
}
ll range_sum(ll a, ll b) {
if (a > b) return 0ll;
ll dif = a - 1, cnt = b - a + 1;
ll ans = ((b - a + 1) * (b - a + 2)) / 2;
ans += ((b - a + 1) * dif);
return ans;
}
string dec_to_bin(ll a) {
string s = "";
for (ll i = a; i > 0; ) {
ll k = i % 2;
i /= 2;
char c = k + 48;
s += c;
}
if (a == 0) {
s = "0";
}
reverse(all(s));
return s;
}
ll bin_to_dec(string s) {
ll num = 0;
for (int i = 0; i < s.size(); i++) {
num *= 2ll;
num += (s[i] - '0');
}
return num;
}
ll factorial_by_mod(ll n, ll mod) {
ll ans = 1;
ll num;
for (ll i = 1; i <= n; ++i) {
num = i % mod;
ans *= num;
ans %= mod;
}
return ans;
}
int isPrime(ll a) {
if (a == 1) return 0;
for (ll i = 2; i * i <= a; i++) {
if (a % i == 0) return 0;
}
return 1;
}
ll binpow(ll a, ll b) {
if (!a) return 0;
ll ans = 1;
while (b) {
if (b & 1) {
ans *= a;
}
b >>= 1;
a *= a;
}
return ans;
}
ll binpow_by_mod(ll a, ll b, ll mod) {
if (!a) return 0;
ll ans = 1;
while (b) {
if (b & 1) {
ans *= a;
ans %= mod;
}
b >>= 1;
a *= a;
a %= mod;
}
return ans;
}
/* -------------------- Solution -------------------- */
const int N = 200005;
ll a[N], sum[N];
int ans[N], p[N], sz[N];
vi g[N], comp[N];
int n, m;
int find_set(int x) {
if (x == p[x]) return x;
return p[x] = find_set(p[x]);
}
void union_sets(int val, int x, int y) {
x = find_set(x), y = find_set(y);
if (x == y) return;
if (sum[y] >= val) {
if (sz[y] > sz[x]) swap(x, y);
p[y] = x;
sz[x] += sz[y];
sum[x] += sum[y];
for (auto elem : comp[y]) comp[x].pub(elem);
}
else {
for (auto elem : comp[y]) ans[elem] = 0;
comp[y].clear();
if (sz[y] > sz[x]) swap(x, y);
p[y] = x;
sz[x] += sz[y];
sum[x] += sum[y];
for (auto elem : comp[y]) comp[x].pub(elem);
}
}
void slv() {
cin >> n >> m;
for (int ind = 1; ind <= n; ++ind) {
cin >> a[ind];
ans[ind] = 1;
sz[ind] = 1;
p[ind] = ind;
comp[ind] = { ind };
sum[ind] = a[ind];
}
vector<pair<pii, pii>> v;
for (int i = 0; i < m; ++i) {
int x, y;
cin >> x >> y;
if (a[x] < a[y]) swap(x, y);
v.pub({ {a[x],a[y]},{x,y} });
}
sort(all(v));
for (auto elem : v) {
union_sets(elem.ff.ff, elem.ss.ff, elem.ss.ss);
}
for (int i = 1; i <= n; ++i) {
cout << ans[i];
}
}
void cs() {
int tstc = 1;
//cin >> tstc;
while (tstc--) {
slv();
}
}
void precalc() {
return;
}
int main() {
fastio();
precalc();
//precision(0);
cs();
return 0;
}
Compilation message
island.cpp: In function 'll range_sum(ll, ll)':
island.cpp:95:21: warning: unused variable 'cnt' [-Wunused-variable]
95 | ll dif = a - 1, cnt = b - a + 1;
| ^~~
island.cpp: In function 'll bin_to_dec(std::string)':
island.cpp:118:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
118 | for (int i = 0; i < s.size(); i++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
14936 KB |
Output is correct |
2 |
Correct |
3 ms |
14936 KB |
Output is correct |
3 |
Correct |
4 ms |
14940 KB |
Output is correct |
4 |
Correct |
4 ms |
14936 KB |
Output is correct |
5 |
Correct |
3 ms |
14940 KB |
Output is correct |
6 |
Correct |
5 ms |
15208 KB |
Output is correct |
7 |
Correct |
4 ms |
14940 KB |
Output is correct |
8 |
Correct |
3 ms |
14940 KB |
Output is correct |
9 |
Correct |
4 ms |
14940 KB |
Output is correct |
10 |
Correct |
5 ms |
14936 KB |
Output is correct |
11 |
Correct |
4 ms |
14940 KB |
Output is correct |
12 |
Correct |
4 ms |
14940 KB |
Output is correct |
13 |
Correct |
4 ms |
15104 KB |
Output is correct |
14 |
Correct |
4 ms |
14940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
14940 KB |
Output is correct |
2 |
Correct |
4 ms |
14936 KB |
Output is correct |
3 |
Correct |
84 ms |
30908 KB |
Output is correct |
4 |
Correct |
85 ms |
29528 KB |
Output is correct |
5 |
Correct |
112 ms |
32068 KB |
Output is correct |
6 |
Correct |
113 ms |
32540 KB |
Output is correct |
7 |
Correct |
103 ms |
33292 KB |
Output is correct |
8 |
Correct |
93 ms |
31060 KB |
Output is correct |
9 |
Correct |
88 ms |
34484 KB |
Output is correct |
10 |
Correct |
75 ms |
29632 KB |
Output is correct |
11 |
Correct |
79 ms |
30132 KB |
Output is correct |
12 |
Correct |
98 ms |
29684 KB |
Output is correct |
13 |
Correct |
79 ms |
30204 KB |
Output is correct |
14 |
Correct |
92 ms |
29680 KB |
Output is correct |
15 |
Correct |
89 ms |
31612 KB |
Output is correct |
16 |
Correct |
67 ms |
30248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
14936 KB |
Output is correct |
2 |
Correct |
102 ms |
33472 KB |
Output is correct |
3 |
Correct |
102 ms |
33464 KB |
Output is correct |
4 |
Correct |
99 ms |
31136 KB |
Output is correct |
5 |
Correct |
76 ms |
30088 KB |
Output is correct |
6 |
Correct |
111 ms |
33120 KB |
Output is correct |
7 |
Correct |
84 ms |
31616 KB |
Output is correct |
8 |
Correct |
92 ms |
31160 KB |
Output is correct |
9 |
Correct |
67 ms |
30768 KB |
Output is correct |
10 |
Correct |
83 ms |
29412 KB |
Output is correct |
11 |
Correct |
93 ms |
30376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
14992 KB |
Output is correct |
2 |
Correct |
138 ms |
31028 KB |
Output is correct |
3 |
Correct |
148 ms |
31508 KB |
Output is correct |
4 |
Correct |
124 ms |
32436 KB |
Output is correct |
5 |
Correct |
110 ms |
33788 KB |
Output is correct |
6 |
Correct |
115 ms |
32204 KB |
Output is correct |
7 |
Correct |
86 ms |
31504 KB |
Output is correct |
8 |
Correct |
73 ms |
29108 KB |
Output is correct |
9 |
Correct |
75 ms |
24400 KB |
Output is correct |
10 |
Correct |
115 ms |
33640 KB |
Output is correct |
11 |
Correct |
101 ms |
30088 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
14936 KB |
Output is correct |
2 |
Correct |
3 ms |
14936 KB |
Output is correct |
3 |
Correct |
4 ms |
14940 KB |
Output is correct |
4 |
Correct |
4 ms |
14936 KB |
Output is correct |
5 |
Correct |
3 ms |
14940 KB |
Output is correct |
6 |
Correct |
5 ms |
15208 KB |
Output is correct |
7 |
Correct |
4 ms |
14940 KB |
Output is correct |
8 |
Correct |
3 ms |
14940 KB |
Output is correct |
9 |
Correct |
4 ms |
14940 KB |
Output is correct |
10 |
Correct |
5 ms |
14936 KB |
Output is correct |
11 |
Correct |
4 ms |
14940 KB |
Output is correct |
12 |
Correct |
4 ms |
14940 KB |
Output is correct |
13 |
Correct |
4 ms |
15104 KB |
Output is correct |
14 |
Correct |
4 ms |
14940 KB |
Output is correct |
15 |
Correct |
3 ms |
14940 KB |
Output is correct |
16 |
Correct |
4 ms |
14936 KB |
Output is correct |
17 |
Correct |
84 ms |
30908 KB |
Output is correct |
18 |
Correct |
85 ms |
29528 KB |
Output is correct |
19 |
Correct |
112 ms |
32068 KB |
Output is correct |
20 |
Correct |
113 ms |
32540 KB |
Output is correct |
21 |
Correct |
103 ms |
33292 KB |
Output is correct |
22 |
Correct |
93 ms |
31060 KB |
Output is correct |
23 |
Correct |
88 ms |
34484 KB |
Output is correct |
24 |
Correct |
75 ms |
29632 KB |
Output is correct |
25 |
Correct |
79 ms |
30132 KB |
Output is correct |
26 |
Correct |
98 ms |
29684 KB |
Output is correct |
27 |
Correct |
79 ms |
30204 KB |
Output is correct |
28 |
Correct |
92 ms |
29680 KB |
Output is correct |
29 |
Correct |
89 ms |
31612 KB |
Output is correct |
30 |
Correct |
67 ms |
30248 KB |
Output is correct |
31 |
Correct |
3 ms |
14936 KB |
Output is correct |
32 |
Correct |
102 ms |
33472 KB |
Output is correct |
33 |
Correct |
102 ms |
33464 KB |
Output is correct |
34 |
Correct |
99 ms |
31136 KB |
Output is correct |
35 |
Correct |
76 ms |
30088 KB |
Output is correct |
36 |
Correct |
111 ms |
33120 KB |
Output is correct |
37 |
Correct |
84 ms |
31616 KB |
Output is correct |
38 |
Correct |
92 ms |
31160 KB |
Output is correct |
39 |
Correct |
67 ms |
30768 KB |
Output is correct |
40 |
Correct |
83 ms |
29412 KB |
Output is correct |
41 |
Correct |
93 ms |
30376 KB |
Output is correct |
42 |
Correct |
4 ms |
14992 KB |
Output is correct |
43 |
Correct |
138 ms |
31028 KB |
Output is correct |
44 |
Correct |
148 ms |
31508 KB |
Output is correct |
45 |
Correct |
124 ms |
32436 KB |
Output is correct |
46 |
Correct |
110 ms |
33788 KB |
Output is correct |
47 |
Correct |
115 ms |
32204 KB |
Output is correct |
48 |
Correct |
86 ms |
31504 KB |
Output is correct |
49 |
Correct |
73 ms |
29108 KB |
Output is correct |
50 |
Correct |
75 ms |
24400 KB |
Output is correct |
51 |
Correct |
115 ms |
33640 KB |
Output is correct |
52 |
Correct |
101 ms |
30088 KB |
Output is correct |
53 |
Correct |
3 ms |
14940 KB |
Output is correct |
54 |
Correct |
4 ms |
15000 KB |
Output is correct |
55 |
Correct |
3 ms |
14940 KB |
Output is correct |
56 |
Correct |
4 ms |
14940 KB |
Output is correct |
57 |
Correct |
4 ms |
15256 KB |
Output is correct |
58 |
Correct |
4 ms |
14940 KB |
Output is correct |
59 |
Correct |
4 ms |
15092 KB |
Output is correct |
60 |
Correct |
4 ms |
15024 KB |
Output is correct |
61 |
Correct |
3 ms |
15164 KB |
Output is correct |
62 |
Correct |
4 ms |
14936 KB |
Output is correct |
63 |
Correct |
5 ms |
15092 KB |
Output is correct |
64 |
Correct |
4 ms |
14940 KB |
Output is correct |
65 |
Correct |
5 ms |
14940 KB |
Output is correct |
66 |
Correct |
4 ms |
14940 KB |
Output is correct |
67 |
Correct |
86 ms |
31636 KB |
Output is correct |
68 |
Correct |
81 ms |
29736 KB |
Output is correct |
69 |
Correct |
102 ms |
32008 KB |
Output is correct |
70 |
Correct |
110 ms |
32704 KB |
Output is correct |
71 |
Correct |
114 ms |
32696 KB |
Output is correct |
72 |
Correct |
95 ms |
31360 KB |
Output is correct |
73 |
Correct |
89 ms |
34484 KB |
Output is correct |
74 |
Correct |
83 ms |
28996 KB |
Output is correct |
75 |
Correct |
86 ms |
30132 KB |
Output is correct |
76 |
Correct |
103 ms |
29632 KB |
Output is correct |
77 |
Correct |
80 ms |
29624 KB |
Output is correct |
78 |
Correct |
84 ms |
29568 KB |
Output is correct |
79 |
Correct |
83 ms |
31156 KB |
Output is correct |
80 |
Correct |
63 ms |
30908 KB |
Output is correct |
81 |
Correct |
118 ms |
33912 KB |
Output is correct |
82 |
Correct |
127 ms |
34496 KB |
Output is correct |
83 |
Correct |
97 ms |
31640 KB |
Output is correct |
84 |
Correct |
93 ms |
29164 KB |
Output is correct |
85 |
Correct |
119 ms |
33972 KB |
Output is correct |
86 |
Correct |
86 ms |
32040 KB |
Output is correct |
87 |
Correct |
77 ms |
31160 KB |
Output is correct |
88 |
Correct |
84 ms |
30656 KB |
Output is correct |
89 |
Correct |
99 ms |
30132 KB |
Output is correct |
90 |
Correct |
127 ms |
31616 KB |
Output is correct |
91 |
Correct |
116 ms |
31420 KB |
Output is correct |
92 |
Correct |
127 ms |
33344 KB |
Output is correct |
93 |
Correct |
122 ms |
34044 KB |
Output is correct |
94 |
Correct |
112 ms |
32008 KB |
Output is correct |
95 |
Correct |
96 ms |
30904 KB |
Output is correct |
96 |
Correct |
88 ms |
29884 KB |
Output is correct |
97 |
Correct |
79 ms |
25284 KB |
Output is correct |
98 |
Correct |
124 ms |
33796 KB |
Output is correct |
99 |
Correct |
101 ms |
30120 KB |
Output is correct |
100 |
Correct |
54 ms |
21716 KB |
Output is correct |
101 |
Correct |
147 ms |
31740 KB |
Output is correct |
102 |
Correct |
101 ms |
29744 KB |
Output is correct |
103 |
Correct |
123 ms |
29764 KB |
Output is correct |
104 |
Correct |
109 ms |
30544 KB |
Output is correct |