#include <bits/stdc++.h>
#define MAX 300001
#define INF LLONG_MAX
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ins insert
#define ff first
#define ss second
#define gett(x,m) get<m>(x)
#define all(a) a.begin(),a.end()
#define lb(a,b) lower_bound(all(a),b)
#define ub(a,b) upper_bound(all(a),b)
#define sortv(a) sort(all(a))
#define sorta(a,sz) sort(a,a+sz)
#define inputar(a,b){\
for(int i=0;i<b;i++){\
cin >> a[i];\
}\
}
#define inputvec(a,b){\
for(int i=0;i<b;i++){\
ll num;\
cin >> num;\
a.pb(num);\
}\
}
#define outputar(a,b){\
for(int i=0;i<b;i++){\
cout << a[i] << " ";\
}\
cout << "\n";\
}
#define outputvec(a){\
for(auto x:a){\
cout << x << " ";\
}\
cout << "\n";\
}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll,ll,ll> tll;
typedef pair<ll,ll> pll;
typedef double db;
typedef long double ldb;
inline void USACO(string filename){
freopen((filename+".in").c_str(),"r",stdin);
freopen((filename+".out").c_str(),"w",stdout);
}
ll n,q,t=1,m,n2,m2,k,cnt=0,a[MAX],b[MAX],d[MAX],d2[MAX],cnte[MAX],x,y,z,x2,y2,z2,res1=0,cnt1,cnt2,cnt3;
ll c[501][501];
ll fact[MAX];
ll inv_fact[MAX];
//char c;
string str[MAX];
string s1,s2;
vector<tuple<ll,ll,ll>> v;
vector<pll> v1,v2,v3,v4;
const int mod = 998244353;
ll modmul(ll x,ll y,ll md){
if(y==1){
return x;
}
if(y%2){
return (x+modmul(x,y-1,md))%md;
}
else{
return (modmul((x+x)%md,y/2,md))%md;
}
}
ll powmod(ll x,ll y,ll md){
x%=md;
if(x==0){
return 0;
}
ll res=1;
while(y){
if(y%2==1){
res*=x;
res%=md;
}
x*=x;
x%=md;
y/=2;
}
return res;
}
ll pow2(ll x,ll y){
if(x==0){
return 0;
}
ll res=1;
while(y>0){
if(y%2==1){
if(res>=1e18/x){
res=1e18;
}
else{
res*=x;
}
}
if(x>=1e18/x){
x=1e18;
}
else{
x*=x;
}
y/=2;
}
return res;
}
ll inv(ll n,ll md){
return powmod(n,md-2,md);
}
ll nCkm(ll n,ll k,ll md){
if(n-k<0){
return 0;
}
return fact[n]*inv_fact[k]%md*inv_fact[n-k]%md;
}
ll nCk(ll x,ll y){
if(x<y){
return 0;
}
ll res=1;
if(y>x-y){
for(int i=y+1;i<=x;i++){
res*=i;
}
for(int i=2;i<=x-y;i++){
res/=i;
}
}
else{
for(int i=x-y+1;i<=x;i++){
res*=i;
}
for(int i=2;i<=y;i++){
res/=i;
}
}
return res;
}
ll countbits(ll x){
ll cnt=0;
while(x){
cnt+=x&1;
x>>=1;
}
return cnt;
}
ll gcd(ll x,ll y){
if(y==0){
return x;
}
return gcd(y,x%y);
}
ll lcm(ll x,ll y){
return x*y/gcd(x,y);
}
bool alpha(char c1,char c2){
ll h1,h2;
if(c1>='a'){
h1=c1-'a';
}
else{
h1=c1-'A';
}
if(c2>='a'){
h2=c2-'a';
}
else{
h2=c2-'A';
}
if(h1==h2){
return c1<c2;
}
else{
return h1<h2;
}
}
ll dx[4]={1,0,0,-1};
ll dy[4]={0,1,-1,0};
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
pll f(pll x,pll y){
if(x.ff>y.ff || (x.ff==y.ff && x.ss<y.ss)){
return mp(x.ff,x.ss);
}
else{
return mp(y.ff,y.ss);
}
}
struct segtree{
int size;
vector<pll> maximum;
/*
void build(vector<int> &a,int x,int lx,int rx){
if(rx-lx==1){
if(lx<(int)a.size()){
maximum[x]=a[lx];
}
return;
}
int m=(lx+rx)/2;
build(a,2*x+1,lx,m);
build(a,2*x+2,m,rx);
maximum[x]=max(maximum[2*x+1],maximum[2*x+2]);
}
void build(vector<int> &a){
build(a,0,0,size);
}
*/
void init(int n){
size=1;
while(size<n){
size*=2;
}
pll p={-INF,-1};
maximum.assign(2*size,p);
}
pll get_max(int l,int r,int x,int lx,int rx){
if(lx>=r || rx<=l){
return mp(-INF,(ll)-1);
}
if(lx>=l && rx<=r){
return maximum[x];
}
pll s1,s2;
int m=(lx+rx)/2;
s1=get_max(l,r,2*x+1,lx,m);
s2=get_max(l,r,2*x+2,m,rx);
return f(s1,s2);
}
pll get_max(int l,int r){
return get_max(l,r,0,0,size);
}
void set(int i,int v,int num,int x,int lx,int rx){
if(rx-lx==1){
maximum[x]=pll(v,num);
return;
}
int m=(lx+rx)/2;
if(i<m){
set(i,v,num,2*x+1,lx,m);
}
else{
set(i,v,num,2*x+2,m,rx);
}
maximum[x]=f(maximum[2*x+1],maximum[2*x+2]);
}
void set(int i,int v,int num){
set(i,v,num,0,0,size);
}
};
struct segtree2{
int size;
vector<ll> xr;
/*
void build(vector<int> &a,int x,int lx,int rx){
if(rx-lx==1){
if(lx<(int)a.size()){
maximum[x]=a[lx];
}
return;
}
int m=(lx+rx)/2;
build(a,2*x+1,lx,m);
build(a,2*x+2,m,rx);
maximum[x]=max(maximum[2*x+1],maximum[2*x+2]);
}
void build(vector<int> &a){
build(a,0,0,size);
}
*/
void init(int n){
size=1;
while(size<n){
size*=2;
}
xr.assign(2*size,0);
}
ll get_xr(int l,int r,int x,int lx,int rx){
if(lx>=r || rx<=l){
return 0;
}
if(lx>=l && rx<=r){
return xr[x];
}
ll s1,s2;
int m=(lx+rx)/2;
s1=get_xr(l,r,2*x+1,lx,m);
s2=get_xr(l,r,2*x+2,m,rx);
return (s1^s2);
}
ll get_xr(int l,int r){
return get_xr(l,r,0,0,size);
}
void set(int i,int v,int x,int lx,int rx){
if(rx-lx==1){
xr[x]=v;
return;
}
int m=(lx+rx)/2;
if(i<m){
set(i,v,2*x+1,lx,m);
}
else{
set(i,v,2*x+2,m,rx);
}
xr[x]=(xr[2*x+1]^xr[2*x+2]);
}
void set(int i,int v){
set(i,v,0,0,size);
}
};
vector<vector<ll>> g;
vector<vector<ll>> vec;
struct dsu{
vector<ll> e;
vector<ll> sum;
void init(int n){
e.resize(n+1,-1);
sum.resize(n+1);
for(int i=1;i<=n;i++){
sum[i]=a[i];
vec[i].pb(i);
}
}
int get(int x){
if(e[x]<0){
return x;
}
else{
return e[x]=get(e[x]);
}
}
bool same_set(int x,int y){
return (get(x)==get(y));
}
int size(int x){
return -e[get(x)];
}
ll get_sum(int x){
return sum[get(x)];
}
bool unite(int x,int y){
x=get(x);
y=get(y);
if(x==y){
return false;
}
if(e[x]>e[y]){
swap(x,y);
}
e[x]+=e[y];
sum[x]+=sum[y];
for(auto z:vec[y]){
vec[x].pb(z);
}
e[y]=x;
return true;
}
};
void solve(){
cin >> n >> m;
g.resize(n+1);
vec.resize(n+1);
vector<vector<ll>> c;
set<ll> st;
map<ll,ll> comp;
for(int i=1;i<=n;i++){
cin >> a[i];
st.ins(a[i]);
}
ll cnt=0;
for(auto x:st){
comp[x]=cnt;
cnt++;
}
c.resize(cnt);
for(int i=1;i<=n;i++){
c[comp[a[i]]].pb(i);
}
for(int i=0;i<m;i++){
cin >> x >> y;
g[x].pb(y);
g[y].pb(x);
}
dsu h;
h.init(n);
for(int i=0;i<cnt;i++){
for(auto y:c[i]){
for(auto z:g[y]){
if(a[z]<=a[y]){
if(h.get_sum(z)<a[y]){
ll rt=h.get(z);
for(auto nd:vec[rt]){
b[nd]=1;
}
vec[rt].clear();
}
h.unite(z,y);
}
}
}
}
for(int i=1;i<=n;i++){
cout << 1-b[i];
}
}
int main(){
//ios::sync_with_stdio(0);
//cin.tie(0);
//cout.tie(0);
//USACO("poetry");
//freopen("input.txt","r",stdin);
//cin >> t;
ll cnt1=1;
while(t--){
solve();
cnt1++;
}
}
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
ifstream fin("template.in");
ofstream fout("template.out");
*/
/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
ifstream fin("template.in");
ofstream fout("template.out");
*/
/*
ll b[51][51];
b[0][0] = 1;
for (int n = 1; n <= 50; ++n){
b[n][0] = b[n][n] = 1;
for (int k = 1; k < n; ++k)
b[n][k] = b[n - 1][k - 1] + b[n - 1][k];
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
16988 KB |
Output is correct |
2 |
Correct |
4 ms |
16988 KB |
Output is correct |
3 |
Correct |
3 ms |
12892 KB |
Output is correct |
4 |
Correct |
7 ms |
17500 KB |
Output is correct |
5 |
Correct |
7 ms |
17496 KB |
Output is correct |
6 |
Correct |
6 ms |
17244 KB |
Output is correct |
7 |
Correct |
8 ms |
17340 KB |
Output is correct |
8 |
Correct |
6 ms |
17496 KB |
Output is correct |
9 |
Correct |
5 ms |
17240 KB |
Output is correct |
10 |
Correct |
7 ms |
17496 KB |
Output is correct |
11 |
Correct |
7 ms |
17752 KB |
Output is correct |
12 |
Correct |
7 ms |
17496 KB |
Output is correct |
13 |
Correct |
5 ms |
17244 KB |
Output is correct |
14 |
Correct |
7 ms |
17244 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
16984 KB |
Output is correct |
2 |
Correct |
3 ms |
12888 KB |
Output is correct |
3 |
Correct |
362 ms |
82888 KB |
Output is correct |
4 |
Correct |
222 ms |
49564 KB |
Output is correct |
5 |
Correct |
422 ms |
83752 KB |
Output is correct |
6 |
Correct |
367 ms |
78296 KB |
Output is correct |
7 |
Correct |
431 ms |
86212 KB |
Output is correct |
8 |
Correct |
312 ms |
50904 KB |
Output is correct |
9 |
Correct |
364 ms |
82240 KB |
Output is correct |
10 |
Correct |
331 ms |
72640 KB |
Output is correct |
11 |
Correct |
219 ms |
50896 KB |
Output is correct |
12 |
Correct |
285 ms |
50144 KB |
Output is correct |
13 |
Correct |
246 ms |
48452 KB |
Output is correct |
14 |
Correct |
225 ms |
49020 KB |
Output is correct |
15 |
Correct |
385 ms |
81864 KB |
Output is correct |
16 |
Correct |
284 ms |
80364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
12888 KB |
Output is correct |
2 |
Correct |
633 ms |
86492 KB |
Output is correct |
3 |
Correct |
533 ms |
79420 KB |
Output is correct |
4 |
Correct |
241 ms |
51136 KB |
Output is correct |
5 |
Correct |
177 ms |
48968 KB |
Output is correct |
6 |
Correct |
569 ms |
86864 KB |
Output is correct |
7 |
Correct |
345 ms |
81612 KB |
Output is correct |
8 |
Correct |
352 ms |
81840 KB |
Output is correct |
9 |
Correct |
272 ms |
80328 KB |
Output is correct |
10 |
Correct |
284 ms |
64664 KB |
Output is correct |
11 |
Correct |
224 ms |
50640 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
12888 KB |
Output is correct |
2 |
Correct |
312 ms |
52568 KB |
Output is correct |
3 |
Correct |
291 ms |
53360 KB |
Output is correct |
4 |
Correct |
317 ms |
55480 KB |
Output is correct |
5 |
Correct |
302 ms |
58460 KB |
Output is correct |
6 |
Correct |
287 ms |
52008 KB |
Output is correct |
7 |
Correct |
214 ms |
52044 KB |
Output is correct |
8 |
Correct |
157 ms |
49552 KB |
Output is correct |
9 |
Correct |
152 ms |
36816 KB |
Output is correct |
10 |
Correct |
277 ms |
59804 KB |
Output is correct |
11 |
Correct |
216 ms |
49492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
16988 KB |
Output is correct |
2 |
Correct |
4 ms |
16988 KB |
Output is correct |
3 |
Correct |
3 ms |
12892 KB |
Output is correct |
4 |
Correct |
7 ms |
17500 KB |
Output is correct |
5 |
Correct |
7 ms |
17496 KB |
Output is correct |
6 |
Correct |
6 ms |
17244 KB |
Output is correct |
7 |
Correct |
8 ms |
17340 KB |
Output is correct |
8 |
Correct |
6 ms |
17496 KB |
Output is correct |
9 |
Correct |
5 ms |
17240 KB |
Output is correct |
10 |
Correct |
7 ms |
17496 KB |
Output is correct |
11 |
Correct |
7 ms |
17752 KB |
Output is correct |
12 |
Correct |
7 ms |
17496 KB |
Output is correct |
13 |
Correct |
5 ms |
17244 KB |
Output is correct |
14 |
Correct |
7 ms |
17244 KB |
Output is correct |
15 |
Correct |
4 ms |
16984 KB |
Output is correct |
16 |
Correct |
3 ms |
12888 KB |
Output is correct |
17 |
Correct |
362 ms |
82888 KB |
Output is correct |
18 |
Correct |
222 ms |
49564 KB |
Output is correct |
19 |
Correct |
422 ms |
83752 KB |
Output is correct |
20 |
Correct |
367 ms |
78296 KB |
Output is correct |
21 |
Correct |
431 ms |
86212 KB |
Output is correct |
22 |
Correct |
312 ms |
50904 KB |
Output is correct |
23 |
Correct |
364 ms |
82240 KB |
Output is correct |
24 |
Correct |
331 ms |
72640 KB |
Output is correct |
25 |
Correct |
219 ms |
50896 KB |
Output is correct |
26 |
Correct |
285 ms |
50144 KB |
Output is correct |
27 |
Correct |
246 ms |
48452 KB |
Output is correct |
28 |
Correct |
225 ms |
49020 KB |
Output is correct |
29 |
Correct |
385 ms |
81864 KB |
Output is correct |
30 |
Correct |
284 ms |
80364 KB |
Output is correct |
31 |
Correct |
2 ms |
12888 KB |
Output is correct |
32 |
Correct |
633 ms |
86492 KB |
Output is correct |
33 |
Correct |
533 ms |
79420 KB |
Output is correct |
34 |
Correct |
241 ms |
51136 KB |
Output is correct |
35 |
Correct |
177 ms |
48968 KB |
Output is correct |
36 |
Correct |
569 ms |
86864 KB |
Output is correct |
37 |
Correct |
345 ms |
81612 KB |
Output is correct |
38 |
Correct |
352 ms |
81840 KB |
Output is correct |
39 |
Correct |
272 ms |
80328 KB |
Output is correct |
40 |
Correct |
284 ms |
64664 KB |
Output is correct |
41 |
Correct |
224 ms |
50640 KB |
Output is correct |
42 |
Correct |
3 ms |
12888 KB |
Output is correct |
43 |
Correct |
312 ms |
52568 KB |
Output is correct |
44 |
Correct |
291 ms |
53360 KB |
Output is correct |
45 |
Correct |
317 ms |
55480 KB |
Output is correct |
46 |
Correct |
302 ms |
58460 KB |
Output is correct |
47 |
Correct |
287 ms |
52008 KB |
Output is correct |
48 |
Correct |
214 ms |
52044 KB |
Output is correct |
49 |
Correct |
157 ms |
49552 KB |
Output is correct |
50 |
Correct |
152 ms |
36816 KB |
Output is correct |
51 |
Correct |
277 ms |
59804 KB |
Output is correct |
52 |
Correct |
216 ms |
49492 KB |
Output is correct |
53 |
Correct |
4 ms |
16984 KB |
Output is correct |
54 |
Correct |
4 ms |
16984 KB |
Output is correct |
55 |
Correct |
3 ms |
12888 KB |
Output is correct |
56 |
Correct |
6 ms |
17496 KB |
Output is correct |
57 |
Correct |
7 ms |
17788 KB |
Output is correct |
58 |
Correct |
5 ms |
17244 KB |
Output is correct |
59 |
Correct |
6 ms |
17496 KB |
Output is correct |
60 |
Correct |
5 ms |
17240 KB |
Output is correct |
61 |
Correct |
5 ms |
17240 KB |
Output is correct |
62 |
Correct |
6 ms |
17496 KB |
Output is correct |
63 |
Correct |
6 ms |
17496 KB |
Output is correct |
64 |
Correct |
6 ms |
17496 KB |
Output is correct |
65 |
Correct |
5 ms |
17240 KB |
Output is correct |
66 |
Correct |
5 ms |
17232 KB |
Output is correct |
67 |
Correct |
356 ms |
83096 KB |
Output is correct |
68 |
Correct |
219 ms |
49676 KB |
Output is correct |
69 |
Correct |
372 ms |
83648 KB |
Output is correct |
70 |
Correct |
376 ms |
78728 KB |
Output is correct |
71 |
Correct |
392 ms |
86192 KB |
Output is correct |
72 |
Correct |
253 ms |
51008 KB |
Output is correct |
73 |
Correct |
350 ms |
82244 KB |
Output is correct |
74 |
Correct |
310 ms |
72640 KB |
Output is correct |
75 |
Correct |
207 ms |
50560 KB |
Output is correct |
76 |
Correct |
236 ms |
50244 KB |
Output is correct |
77 |
Correct |
211 ms |
48708 KB |
Output is correct |
78 |
Correct |
189 ms |
48840 KB |
Output is correct |
79 |
Correct |
368 ms |
81520 KB |
Output is correct |
80 |
Correct |
283 ms |
80448 KB |
Output is correct |
81 |
Correct |
648 ms |
86304 KB |
Output is correct |
82 |
Correct |
470 ms |
79588 KB |
Output is correct |
83 |
Correct |
233 ms |
51184 KB |
Output is correct |
84 |
Correct |
195 ms |
48796 KB |
Output is correct |
85 |
Correct |
615 ms |
86968 KB |
Output is correct |
86 |
Correct |
342 ms |
81696 KB |
Output is correct |
87 |
Correct |
326 ms |
81532 KB |
Output is correct |
88 |
Correct |
286 ms |
64708 KB |
Output is correct |
89 |
Correct |
209 ms |
50640 KB |
Output is correct |
90 |
Correct |
290 ms |
52500 KB |
Output is correct |
91 |
Correct |
302 ms |
53108 KB |
Output is correct |
92 |
Correct |
304 ms |
55604 KB |
Output is correct |
93 |
Correct |
304 ms |
58560 KB |
Output is correct |
94 |
Correct |
290 ms |
51912 KB |
Output is correct |
95 |
Correct |
211 ms |
51460 KB |
Output is correct |
96 |
Correct |
158 ms |
49700 KB |
Output is correct |
97 |
Correct |
154 ms |
36812 KB |
Output is correct |
98 |
Correct |
259 ms |
59840 KB |
Output is correct |
99 |
Correct |
217 ms |
49392 KB |
Output is correct |
100 |
Correct |
82 ms |
24144 KB |
Output is correct |
101 |
Correct |
584 ms |
77304 KB |
Output is correct |
102 |
Correct |
231 ms |
47808 KB |
Output is correct |
103 |
Correct |
443 ms |
65988 KB |
Output is correct |
104 |
Correct |
666 ms |
81772 KB |
Output is correct |