This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define ii pair<ll,ll>
#define iii pair<ll,ii>
#define F first
#define S second
const ll N = 1e6+5;
int main(){
set<ii>x[N],y[N];
ll n;
cin>>n;
ll ans[n] = {0};
set<iii>ek;
f(i,0,n){
ll a,b;
cin>>a>>b;
ek.insert(iii(i,ii(a,b)));
x[a].insert(ii(b,i));
y[b].insert(ii(a,i));
}
while(!ek.empty()){
auto it = ek.begin();
ll a = (*it).S.F,b = (*it).S.S;
if(x[a].size() > 1){
for(auto z:x[a]){
ek.erase(iii(z.S,ii(a,z.F)));
y[z.F].erase(ii(a,z.S));
}
ii A = (*x[a].begin()),B = (*x[a].rbegin());
ans[A.S] = ans[B.S] = 1;
x[a].clear();
y[A.F].insert(ii(a,A.S));
y[B.F].insert(ii(a,B.S));
}
else if(y[b].size() > 1){
for(auto z:y[b]){
ek.erase(iii(z.S,ii(z.F,b)));
x[z.F].erase(ii(b,z.S));
}
ii A = (*y[b].begin()),B = (*y[b].rbegin());
ans[A.S] = ans[B.S] = 1;
y[b].clear();
x[A.F].insert(ii(b,A.S));
x[B.F].insert(ii(b,B.S));
}
else{
ans[(*it).F] = 1;
ek.erase((*it));
}
}
f(i,0,n){
cout<<ans[i];
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |