#include <bits/stdc++.h>
using namespace std;
#define vt vector
#define pb push_back
#define all(x) x.begin(),x.end()
#define FORR1(x) for(int i = 0; i < (x); i++)
#define FORR2(j,x) for(int (j) = 0; (j) < (x); (j)++)
#define f first
#define s second
#define MOD 998244353
#define INF INT_MAX
typedef vt<int> vi;
typedef vt<long long> vl;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ll,int> pli;
struct Segtree{
vl arr;
vl lz1;
vl lz2;
int sz = 1;
void init(int n, vl cop) {
while(sz<n)sz*=2;
arr.resize(2*sz);
lz1.resize(2*sz);
lz2.resize(2*sz);
FORR1(n){
arr[sz+i] = cop[i];
}
FORR1(sz-n){
arr[sz+i+n] = 0;
}
for(int i = sz-1; i>0; i--){
arr[i] = arr[2*i]+arr[2*i+1];
}
FORR1(2*sz){
lz1[i] = lz2[i] = 0;
}
}
void pushlazy(int x, int lth){
if(lth==1){
arr[x] += lz1[x];
lz1[x] = 0;
lz2[x] = 0;
return;
}
arr[x] += lz1[x]*lth + (((ll)lth*(lth-1))>>1)*lz2[x];
lz1[2*x] +=lz1[x];
lz2[2*x] += lz2[x];
lz1[2*x+1] += lz1[x]+(lth>>1)*lz2[x];
lz2[2*x+1] += lz2[x];
lz1[x] = lz2[x] = 0;
}
void add(int index, int val){
int cur = index+sz;
while(cur!=0){
arr[cur]+=val;
cur>>=1;
}
}
ll get(int l, int r, int x, int lx, int rx){
if(lx>r||l>rx){
return 0;
}else if(l<=lx && r>=rx){
pushlazy(x,rx-lx+1);
return arr[x];
}else{
pushlazy(x,rx-lx+1);
int mid = (lx+rx)>>1;
return get(l,r,2*x,lx,mid)+get(l,r,2*x+1,mid+1,rx);
}
}
ll get(int l, int r){
return get(l,r,1,0,sz-1);
}
void set1(int l, int r, int x, int lx, int rx){
pushlazy(x,rx-lx+1);
if(l>rx||r<lx){
return;
}else if(l<=lx&&r>=rx){
lz1[x] = 1+lx-l;
lz2[x] = 1;
pushlazy(x,rx-lx+1);
}else{
int mid = (lx+rx)>>1;
set1(l,r,2*x,lx,mid);
set1(l,r,2*x+1,mid+1,rx);
arr[x] = arr[2*x]+arr[2*x+1];
}
}
void set1(int l, int r){
set1(l,r,1,0,sz-1);
}
};
int pp[200005];
ll sums[200005];
int vals[200005];
vi up[200005];
vi dn[200005];
bool ans[200005];
set<pli> st[200005];
int find(int x){
return (x==pp[x] ? x : pp[x] = find(pp[x]));
}
void join(int a, int b){
int u = find(a), v = find(b);
if(u==v)return;
if(st[u].size()<st[v].size())swap(u,v);
for(auto& e: st[v])st[u].insert(e);
sums[u]+=sums[v];
pp[v] = u;
}
int go[200005];
void solve() {
int n, m;
cin>>n>>m;
FORR1(n)cin>>vals[i];
FORR1(m){
int u, v;
cin>>u>>v;u--;v--;
if(make_pair(vals[u],u)>make_pair(vals[v],v)){
up[v].pb(u);
dn[u].pb(v);
}else{
up[u].pb(v);
dn[v].pb(u);
}
}
vt<pli> arr(n);
FORR1(n)arr[i] = {vals[i],i};
sort(all(arr));
FORR1(n){
pp[i] = i;
sums[i] = vals[i];
go[i] = -1;
}
FORR1(n){
for(auto& e: up[i]){
st[i].insert({vals[e],e});
}
}
FORR1(n){
int x = arr[i].s;
for(auto& e: dn[x]){
join(x,e);
}
int u = find(x);
if(dn[x].size()!=0)st[u].erase(st[u].find(arr[i]));
if(!st[u].empty()){
auto it = *st[u].begin();
if(sums[u]>=it.f){
go[x] = it.s;
}
}
}
ans[arr[n-1].s] = 1;
for(int i = n-2; i>=0; i--){
int x = arr[i].s;
if(go[x]!=-1&&ans[go[x]]){
ans[x] = 1;
}else{
ans[x] = 0;
}
}
FORR1(n)cout<<ans[i];
cout<<'\n';
}
int main(){
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19028 KB |
Output is correct |
2 |
Correct |
12 ms |
19028 KB |
Output is correct |
3 |
Correct |
10 ms |
19120 KB |
Output is correct |
4 |
Correct |
12 ms |
19404 KB |
Output is correct |
5 |
Correct |
13 ms |
19412 KB |
Output is correct |
6 |
Correct |
11 ms |
19396 KB |
Output is correct |
7 |
Correct |
11 ms |
19412 KB |
Output is correct |
8 |
Correct |
11 ms |
19412 KB |
Output is correct |
9 |
Correct |
11 ms |
19412 KB |
Output is correct |
10 |
Correct |
11 ms |
19412 KB |
Output is correct |
11 |
Correct |
11 ms |
19396 KB |
Output is correct |
12 |
Correct |
11 ms |
19412 KB |
Output is correct |
13 |
Correct |
10 ms |
19412 KB |
Output is correct |
14 |
Correct |
11 ms |
19412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
19132 KB |
Output is correct |
2 |
Correct |
10 ms |
19028 KB |
Output is correct |
3 |
Correct |
194 ms |
54180 KB |
Output is correct |
4 |
Correct |
219 ms |
52908 KB |
Output is correct |
5 |
Correct |
213 ms |
52556 KB |
Output is correct |
6 |
Correct |
225 ms |
53600 KB |
Output is correct |
7 |
Correct |
217 ms |
53616 KB |
Output is correct |
8 |
Correct |
287 ms |
57540 KB |
Output is correct |
9 |
Correct |
173 ms |
52812 KB |
Output is correct |
10 |
Correct |
144 ms |
49812 KB |
Output is correct |
11 |
Correct |
218 ms |
49476 KB |
Output is correct |
12 |
Correct |
233 ms |
54040 KB |
Output is correct |
13 |
Correct |
199 ms |
54460 KB |
Output is correct |
14 |
Correct |
204 ms |
54780 KB |
Output is correct |
15 |
Correct |
201 ms |
55952 KB |
Output is correct |
16 |
Correct |
106 ms |
54936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19028 KB |
Output is correct |
2 |
Correct |
255 ms |
51688 KB |
Output is correct |
3 |
Correct |
280 ms |
51856 KB |
Output is correct |
4 |
Correct |
212 ms |
56020 KB |
Output is correct |
5 |
Correct |
200 ms |
54528 KB |
Output is correct |
6 |
Correct |
261 ms |
51788 KB |
Output is correct |
7 |
Correct |
217 ms |
56072 KB |
Output is correct |
8 |
Correct |
220 ms |
56064 KB |
Output is correct |
9 |
Correct |
106 ms |
54908 KB |
Output is correct |
10 |
Correct |
188 ms |
49644 KB |
Output is correct |
11 |
Correct |
216 ms |
50712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
19028 KB |
Output is correct |
2 |
Correct |
296 ms |
52712 KB |
Output is correct |
3 |
Correct |
280 ms |
51756 KB |
Output is correct |
4 |
Correct |
291 ms |
52108 KB |
Output is correct |
5 |
Correct |
254 ms |
51996 KB |
Output is correct |
6 |
Correct |
242 ms |
53516 KB |
Output is correct |
7 |
Correct |
209 ms |
50452 KB |
Output is correct |
8 |
Correct |
148 ms |
57932 KB |
Output is correct |
9 |
Correct |
206 ms |
47180 KB |
Output is correct |
10 |
Correct |
240 ms |
50352 KB |
Output is correct |
11 |
Correct |
208 ms |
50680 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
19028 KB |
Output is correct |
2 |
Correct |
12 ms |
19028 KB |
Output is correct |
3 |
Correct |
10 ms |
19120 KB |
Output is correct |
4 |
Correct |
12 ms |
19404 KB |
Output is correct |
5 |
Correct |
13 ms |
19412 KB |
Output is correct |
6 |
Correct |
11 ms |
19396 KB |
Output is correct |
7 |
Correct |
11 ms |
19412 KB |
Output is correct |
8 |
Correct |
11 ms |
19412 KB |
Output is correct |
9 |
Correct |
11 ms |
19412 KB |
Output is correct |
10 |
Correct |
11 ms |
19412 KB |
Output is correct |
11 |
Correct |
11 ms |
19396 KB |
Output is correct |
12 |
Correct |
11 ms |
19412 KB |
Output is correct |
13 |
Correct |
10 ms |
19412 KB |
Output is correct |
14 |
Correct |
11 ms |
19412 KB |
Output is correct |
15 |
Correct |
9 ms |
19132 KB |
Output is correct |
16 |
Correct |
10 ms |
19028 KB |
Output is correct |
17 |
Correct |
194 ms |
54180 KB |
Output is correct |
18 |
Correct |
219 ms |
52908 KB |
Output is correct |
19 |
Correct |
213 ms |
52556 KB |
Output is correct |
20 |
Correct |
225 ms |
53600 KB |
Output is correct |
21 |
Correct |
217 ms |
53616 KB |
Output is correct |
22 |
Correct |
287 ms |
57540 KB |
Output is correct |
23 |
Correct |
173 ms |
52812 KB |
Output is correct |
24 |
Correct |
144 ms |
49812 KB |
Output is correct |
25 |
Correct |
218 ms |
49476 KB |
Output is correct |
26 |
Correct |
233 ms |
54040 KB |
Output is correct |
27 |
Correct |
199 ms |
54460 KB |
Output is correct |
28 |
Correct |
204 ms |
54780 KB |
Output is correct |
29 |
Correct |
201 ms |
55952 KB |
Output is correct |
30 |
Correct |
106 ms |
54936 KB |
Output is correct |
31 |
Correct |
10 ms |
19028 KB |
Output is correct |
32 |
Correct |
255 ms |
51688 KB |
Output is correct |
33 |
Correct |
280 ms |
51856 KB |
Output is correct |
34 |
Correct |
212 ms |
56020 KB |
Output is correct |
35 |
Correct |
200 ms |
54528 KB |
Output is correct |
36 |
Correct |
261 ms |
51788 KB |
Output is correct |
37 |
Correct |
217 ms |
56072 KB |
Output is correct |
38 |
Correct |
220 ms |
56064 KB |
Output is correct |
39 |
Correct |
106 ms |
54908 KB |
Output is correct |
40 |
Correct |
188 ms |
49644 KB |
Output is correct |
41 |
Correct |
216 ms |
50712 KB |
Output is correct |
42 |
Correct |
9 ms |
19028 KB |
Output is correct |
43 |
Correct |
296 ms |
52712 KB |
Output is correct |
44 |
Correct |
280 ms |
51756 KB |
Output is correct |
45 |
Correct |
291 ms |
52108 KB |
Output is correct |
46 |
Correct |
254 ms |
51996 KB |
Output is correct |
47 |
Correct |
242 ms |
53516 KB |
Output is correct |
48 |
Correct |
209 ms |
50452 KB |
Output is correct |
49 |
Correct |
148 ms |
57932 KB |
Output is correct |
50 |
Correct |
206 ms |
47180 KB |
Output is correct |
51 |
Correct |
240 ms |
50352 KB |
Output is correct |
52 |
Correct |
208 ms |
50680 KB |
Output is correct |
53 |
Correct |
12 ms |
19136 KB |
Output is correct |
54 |
Correct |
11 ms |
19136 KB |
Output is correct |
55 |
Correct |
11 ms |
19028 KB |
Output is correct |
56 |
Correct |
11 ms |
19400 KB |
Output is correct |
57 |
Correct |
12 ms |
19464 KB |
Output is correct |
58 |
Correct |
11 ms |
19364 KB |
Output is correct |
59 |
Correct |
11 ms |
19412 KB |
Output is correct |
60 |
Correct |
10 ms |
19412 KB |
Output is correct |
61 |
Correct |
10 ms |
19396 KB |
Output is correct |
62 |
Correct |
11 ms |
19396 KB |
Output is correct |
63 |
Correct |
11 ms |
19444 KB |
Output is correct |
64 |
Correct |
10 ms |
19412 KB |
Output is correct |
65 |
Correct |
12 ms |
19412 KB |
Output is correct |
66 |
Correct |
11 ms |
19340 KB |
Output is correct |
67 |
Correct |
188 ms |
54048 KB |
Output is correct |
68 |
Correct |
195 ms |
53056 KB |
Output is correct |
69 |
Correct |
222 ms |
52448 KB |
Output is correct |
70 |
Correct |
213 ms |
53560 KB |
Output is correct |
71 |
Correct |
241 ms |
53696 KB |
Output is correct |
72 |
Correct |
261 ms |
57500 KB |
Output is correct |
73 |
Correct |
191 ms |
52700 KB |
Output is correct |
74 |
Correct |
141 ms |
49600 KB |
Output is correct |
75 |
Correct |
225 ms |
49436 KB |
Output is correct |
76 |
Correct |
251 ms |
54032 KB |
Output is correct |
77 |
Correct |
196 ms |
54664 KB |
Output is correct |
78 |
Correct |
201 ms |
54752 KB |
Output is correct |
79 |
Correct |
191 ms |
55972 KB |
Output is correct |
80 |
Correct |
107 ms |
54988 KB |
Output is correct |
81 |
Correct |
256 ms |
51744 KB |
Output is correct |
82 |
Correct |
257 ms |
51788 KB |
Output is correct |
83 |
Correct |
213 ms |
56040 KB |
Output is correct |
84 |
Correct |
212 ms |
54508 KB |
Output is correct |
85 |
Correct |
256 ms |
51876 KB |
Output is correct |
86 |
Correct |
225 ms |
56096 KB |
Output is correct |
87 |
Correct |
217 ms |
55960 KB |
Output is correct |
88 |
Correct |
177 ms |
49588 KB |
Output is correct |
89 |
Correct |
212 ms |
50676 KB |
Output is correct |
90 |
Correct |
275 ms |
52708 KB |
Output is correct |
91 |
Correct |
311 ms |
51788 KB |
Output is correct |
92 |
Correct |
278 ms |
51868 KB |
Output is correct |
93 |
Correct |
247 ms |
51756 KB |
Output is correct |
94 |
Correct |
259 ms |
53580 KB |
Output is correct |
95 |
Correct |
178 ms |
50416 KB |
Output is correct |
96 |
Correct |
148 ms |
58036 KB |
Output is correct |
97 |
Correct |
208 ms |
47168 KB |
Output is correct |
98 |
Correct |
234 ms |
50392 KB |
Output is correct |
99 |
Correct |
205 ms |
50668 KB |
Output is correct |
100 |
Correct |
110 ms |
36676 KB |
Output is correct |
101 |
Correct |
292 ms |
51936 KB |
Output is correct |
102 |
Correct |
250 ms |
55244 KB |
Output is correct |
103 |
Correct |
293 ms |
55356 KB |
Output is correct |
104 |
Correct |
303 ms |
53760 KB |
Output is correct |