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 int long long
struct sommet {
int x,y,ordreParc;
bool operator < (const sommet& autre) const {
if (x!=autre.x) {
return (x<autre.x);
}
return (y<autre.y);
}
};
const int INFINI=1000*1000*1000+6,TAILLE_MAX=200*1000+5,COORD_MAX=1000+5;
int nbPoints,maxX,nbImpair;
pair<int,int> initPoint[TAILLE_MAX];
pair<int,int> points[TAILLE_MAX];
int cumu[COORD_MAX][COORD_MAX];
int emboite[TAILLE_MAX];
set<pair<int,int>> enCours[2];
void fusion(int deb,int fin,int pari) {
set<pair<int,int>>::iterator it;
enCours[pari].insert({deb,fin});
nbImpair+=(fin-deb)%2;
it=enCours[pari].lower_bound({fin,-INFINI});
int nouvDeb,nouvFin;
if ((*it).first==fin) {
nbImpair-=((*it).second-(*it).first)%2;
nbImpair-=(fin-deb)%2;
nouvFin=(*it).second;
enCours[pari].erase(it);
it=enCours[pari].lower_bound({deb,fin});
enCours[pari].erase(it);
fin=nouvFin;
enCours[pari].insert({deb,fin});
nbImpair+=(fin-deb)%2;
}
it=enCours[pari].lower_bound({deb,fin});
it--;
if ((*it).second==deb) {
nbImpair-=((*it).second-(*it).first)%2;
nbImpair-=(fin-deb)%2;
nouvDeb=(*it).first;
enCours[pari].erase(it);
it=enCours[pari].lower_bound({deb,fin});
enCours[pari].erase(it);
deb=nouvDeb;
enCours[pari].insert({deb,fin});
nbImpair+=(fin-deb)%2;
}
}
void suppr(int deb,int fin,int pari) {
set<pair<int,int>>::iterator it=enCours[pari].lower_bound({deb,fin});
if ((*it).first==deb) {
if ((*it).second==fin) {
nbImpair-=(fin-deb)%2;
enCours[pari].erase(it);
}
else {
nbImpair-=((*it).second-deb)%2;
deb=fin;
fin=(*it).second;
enCours[pari].erase(it);
nbImpair+=(fin-deb)%2;
enCours[pari].insert({deb,fin});
}
}
else {
it--;
if ((*it).second==fin) {
nbImpair-=(fin-(*it).first)%2;
fin=deb;
deb=(*it).first;
enCours[pari].erase(it);
nbImpair+=(fin-deb)%2;
enCours[pari].insert({deb,fin});
}
else {
int premDeb=(*it).first,dernFin=(*it).second;
nbImpair-=(dernFin-premDeb)%2;
enCours[pari].erase(it);
enCours[pari].insert({premDeb,deb});
enCours[pari].insert({fin,dernFin});
nbImpair+=(deb-premDeb)%2;
nbImpair+=(dernFin-fin)%2;
}
}
}
bool intersecte(int deb,int fin,int pari) {
set<pair<int,int>>::iterator it=enCours[pari].lower_bound({fin,-INFINI});
it--;
if ((*it).second>deb) {
return true;
}
return false;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>nbPoints>>maxX;
int xNouv,yNouv,posMin=0,xMin=INFINI,yMin=INFINI,maxY=0,somX=0;
for (int i=0;i<nbPoints;i++) {
cin>>xNouv>>yNouv;
if (xNouv<xMin or (xNouv==xMin and yNouv<yMin)) {
posMin=i;
xMin=xNouv;
yMin=yNouv;
}
maxY=max(maxY,yNouv);
somX+=xNouv%2;
initPoint[i]={xNouv,yNouv};
}
int posCour,direc=-1,nbPris=1;
points[0]={xMin,yMin};
for (int i=1;i<=nbPoints;i++) {
posCour=(posMin+i)%nbPoints;
if (points[nbPris-1].first==initPoint[posCour].first) {
if (direc==0) {
points[nbPris-1].second=initPoint[posCour].second;
}
else {
direc=0;
points[nbPris]=initPoint[posCour];
nbPris++;
}
}
else {
if (direc==1) {
points[nbPris-1].first=initPoint[posCour].first;
}
else {
direc=1;
points[nbPris]=initPoint[posCour];
nbPris++;
}
}
}
nbPoints=nbPris;
if (direc==0) {
for (int i=0;i<nbPoints/2;i++) {
swap(points[i],points[nbPoints-1-i]);
}
}
int rep=0;
vector<sommet> somTri;
for (int i=0;i<nbPoints-1;i++) {
somTri.push_back({points[i].first,points[i].second,i});
}
somTri.push_back({INFINI,INFINI,nbPoints});
sort(somTri.begin(),somTri.end());
for (int i=0;i<2;i++) {
enCours[i].insert({-INFINI,-42});
enCours[i].insert({INFINI,42});
}
for (int i=0;i<nbPoints-1;i+=2) {
if ((int)enCours[0].size()==2 and (i==0 or somTri[i].x!=somTri[i-2].x)) {
if (somTri[i].x%2==0) {
rep=max(rep,somTri[i].x-1);
}
else {
rep=max(rep,somTri[i].x);
}
}
if ((int)enCours[1].size()==2 and (i==0 or somTri[i].x!=somTri[i-2].x)) {
if (somTri[i].x%2==0) {
rep=max(rep,somTri[i].x);
}
else {
rep=max(rep,somTri[i].x-1);
}
}
if (somTri[i].ordreParc<somTri[i+1].ordreParc) {
fusion(somTri[i].y,somTri[i+1].y,somTri[i].x%2);
}
else {
if (intersecte(somTri[i].y,somTri[i+1].y,1-somTri[i].x%2)) {
cout<<rep<<endl;
return 0;
}
suppr(somTri[i].y,somTri[i+1].y,somTri[i].x%2);
}
if (somTri[i].x!=somTri[i+2].x and nbImpair>0) {
cout<<rep<<endl;
return 0;
}
}
cout<<maxX<<endl;
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... |