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>
#define ll long long
#define pb push_back
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
using namespace std;
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a){os << '{';for(int i=0;i<sz(a);i++){if(i>0&&i<sz(a))os << ", ";os << a[i];}os<<'}';return os;}
void answer(std::vector<int> C, std::vector<int> X, std::vector<int> Y);
struct node{
int x,y;
node(){x=-1;y=-1;}
};
const int NMAX=6e5+5;
vector<node> graf(NMAX);
vector<int> flipped(NMAX);
vector<int> skips;
int stigao;
void markskips(vector<int> poz,int koliko)
{
if(koliko==0)
return;
vector<int> levo,desno;
for(int i=0;i<(int)poz.size();i++)
if(i%2)
desno.pb(poz[i]);
else
levo.pb(poz[i]);
if((int)levo.size()<=koliko)
for(auto p:levo)
skips[p]=1;
else
markskips(levo,koliko);
if((int)levo.size()<koliko)
markskips(desno,koliko-(int)levo.size());
}
void build(int tr,vector<int> izlazi,int skip,int sta)
{
int ukupno=izlazi.size()+skip;
assert(ukupno%2==0);
if(ukupno==2)
{
if(skip)
{
assert(skip==1);
graf[tr].x=sta;
graf[tr].y=izlazi[0];
}
else
{
graf[tr].x=izlazi[0];
graf[tr].y=izlazi[1];
}
return;
}
if(skip>=ukupno/2)
{
graf[tr].x=sta;
graf[tr].y=stigao;
stigao++;
build(graf[tr].y,izlazi,skip-ukupno/2,sta);
return;
}
skips.resize(ukupno);
fill(all(skips),0);
vector<int> pozicije;
for(int i=0;i<ukupno;i++)
pozicije.pb(i);
markskips(pozicije,skip);
vector<int> levo,desno;
int trr=0;
for(int i=0;i<ukupno;i++)
{
if(i%2)
desno.pb(izlazi[trr++]),assert(!skips[i]);
else
if(!skips[i])
levo.pb(izlazi[trr++]);
}
graf[tr].x=stigao;
stigao++;
build(graf[tr].x,levo,skip,sta);
graf[tr].y=stigao;
stigao++;
build(graf[tr].y,desno,0,sta);
}
void construct(int i,vector<int> d)
{
//cout << i << d << endl;
if(d.size()==0)
d.pb(0);
if(d.size()==1)
{
graf[i].x=d[0];
return;
}
graf[i].x=stigao;
stigao++;
int sz=2;
while(sz<(int)d.size())
sz*=2;
build(graf[i].x,d,sz-d.size(),graf[i].x);
}
void create_circuit(int m, vector<int> a)
{
int n=a.size();
vector<vector<int> > ide(m+1);
for(int i=0;i<=m;i++)
graf[i].y=-1;
graf[0].x=a[0];
for(int i=1;i<n;i++)
ide[a[i-1]].pb(a[i]);
ide[a.back()].pb(0);
stigao=m+1;
for(int i=1;i<=m;i++)
construct(i,ide[i]);
vector<int> A,X,Y;
for(int i=0;i<=m;i++)
if(graf[i].x>m)
A.pb(m-graf[i].x);
else
A.pb(graf[i].x);
int zbir=0;
for(int i=1;i<=m;i++)
zbir+=ide[i].size();
for(int i=m+1;i<stigao;i++)
{
if(graf[i].x>m)
X.pb(m-graf[i].x);
else
X.pb(graf[i].x);
if(graf[i].y>m)
Y.pb(m-graf[i].y);
else
Y.pb(graf[i].y);
}
answer(A,X,Y);
}
# | 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... |