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<iostream>
#include<stack>
#include<map>
#include<vector>
#include<string>
#include<unordered_map>
#include <queue>
#include<cstring>
#include<limits.h>
#include<cmath>
#include<set>
#include<algorithm>
#include<bitset>
using namespace std;
#define ll long long
#define f first
#define endl "\n"
#define s second
#define pii pair<int,int>
#define ppii pair<pii,int>
#define pb push_back
#define fastio ios::sync_with_stdio(false);cin.tie(NULL);
#define int long long
#define mod 9871
const int mxn=1e6,inf=1e7;
vector<pii>x[mxn+10];
vector<pii>y[mxn+10];
pii cx[mxn+10];
int cy[mxn+10];
string ans="";
void update(int xx,int di){
bool yes=true;
if(di){
while(cx[xx].f<cx[xx].s){
yes=true;
if(cy[x[xx][cx[xx].f].f]==-1){
ans[x[xx][cx[xx].f].s]='1';
cy[x[xx][cx[xx].f].f]=0;
}
else{
if(cy[x[xx][cx[xx].f].f]==0)cy[x[xx][cx[xx].f].f]=xx,ans[x[xx][cx[xx].f].s]='1';
else if(cy[x[xx][cx[xx].f].f]<xx){
int nx=cy[x[xx][cx[xx].f].f];
if(x[nx][cx[nx].f].f==x[xx][cx[xx].f].f){
cy[x[xx][cx[xx].f].f]=xx;
ans[x[nx][cx[nx].f].s]='0';
ans[x[xx][cx[xx].f].s]='1';
update(nx,1);
}
else if(x[nx][cx[nx].s].f==x[xx][cx[xx].f].f){
cy[x[xx][cx[xx].f].f]=xx;
ans[x[nx][cx[nx].s].s]='0';
ans[x[xx][cx[xx].f].s]='1';
update(nx,0);
}
}
else cx[xx].f++,yes=false;;
}
if(yes)break;
}
return;
}
while(cx[xx].f<cx[xx].s){
yes=true;
if(cy[x[xx][cx[xx].s].f]==-1){
ans[x[xx][cx[xx].s].s]='1';
cy[x[xx][cx[xx].s].f]=0;
}
else{
if(cy[x[xx][cx[xx].s].f]==0)cy[x[xx][cx[xx].s].f]=xx,ans[x[xx][cx[xx].s].s]='1';
else if(cy[x[xx][cx[xx].s].f]<xx){
int nx=cy[x[xx][cx[xx].s].f];
if(x[nx][cx[nx].f].f==x[xx][cx[xx].s].f){
cy[x[xx][cx[xx].s].f]=xx;
ans[x[nx][cx[nx].f].s]='0';
ans[x[xx][cx[xx].s].s]='1';
update(nx,1);
}
else if(x[nx][cx[nx].s].f==x[xx][cx[xx].s].f){
cy[x[xx][cx[xx].s].f]=xx;
ans[x[nx][cx[nx].s].s]='0';
ans[x[xx][cx[xx].s].s]='1';
update(nx,0);
}
}
else cx[xx].s--,yes=false;;
}
if(yes)break;
}
}
int32_t main(){
fastio
int n;cin>>n;
vector<ppii>v(n);
for(int i=0;i<n;i++)ans+='0';
for(int i=0;i<n;i++)cin>>v[i].f.f>>v[i].f.s,v[i].s=i;
sort(v.begin(),v.end());
for(auto i:v)x[i.f.f].pb({i.f.s,i.s});
for(int i=0;i<=mxn;i++)cx[i]={-1,-1},cy[i]=-1;
for(int i=1;i<=mxn;i++){
if(x[i].size()==0)continue;
cx[i].f=0;
cx[i].s=x[i].size()-1;
update(i,1);
update(i,0);
}
cout<<ans;
return 0;
}
# | 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... |