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 "doll.h"
#include<bits/stdc++.h>
using namespace std;
vector<int> X(1),Y(1);
vector<int> AA;
int nxt=-2;
void build_tree(int id,int pot,int l,int r);
int try_add(int l,int r,int pot)
{
//cerr<<"try "<<l<<" "<<r<<" "<<pot<<"\n\n";
if(r<l)
return -1;
if(pot==0)
return AA[l];
X.push_back(0);
Y.push_back(0);
int id=nxt;
nxt--;
build_tree(id,pot,l,r);
return id;
}
void build_tree(int id,int pot,int l,int r)
{
int i=-id-1;
//cerr<<id<<" "<<i<<" "<<pot<<" "<<l<<" "<<r<<"\n";
//for(int j=l;j<=r;j++)
// cerr<<AA[j]<<" ";
//cerr<<"\n\n";
vector<int> B[2];
int j=l;
for(int it=0;it<2*pot;it++)
{
if(it%2==1 || it/2>=2*pot-(r-l+1))
B[it%2].push_back(AA[j++]);
}
int mid=l+(int)B[0].size()-1;
for(j=0;j<B[0].size();j++)
AA[l+j]=B[0][j];
for(j=0;j<B[1].size();j++)
AA[mid+1+j]=B[1][j];
int xd=try_add(l,mid,pot/2);
X[i]=xd;
xd=try_add(mid+1,r,pot/2);
Y[i]=xd;
return;
}
void create_circuit(int M,vector<int> A)
{
if(A.size()==1)
{
vector<int> ans0(M+1);
ans0[0]=A[0];
for(int i=1;i<=M;i++)
ans0[i]=0;
answer(ans0,vector<int>(0),vector<int>(0));
return;
}
vector<int> C(M+1);
C[0]=A[0];
for(int i=1;i<=M;i++)
C[i]=-1;
for(int i=0;i<A.size()-1;i++)
A[i]=A[i+1];
A.back()=0;
int pot=1;
for(pot=1;2*pot<A.size();pot*=2);
AA=A;
build_tree(-1,pot,0,A.size()-1);
vector<bool> st(X.size());
for(auto v:A)
{
int x=-1;
while(true)
{
int *e;
if(st[-x-1])
e=&(Y[-x-1]);
else
e=&(X[-x-1]);
st[-x-1]=!st[-x-1];
if(*e>=0)
{
(*e)=v;
break;
}
x=*e;
}
}
//cerr<<"C:\n";
//for(auto v:C)
// cerr<<v<<" ";
//cerr<<"\n";
//cerr<<"X,Y:\n";
//for(auto v:X)
// cerr<<v<<" ";
//cerr<<"\n";
//for(auto v:Y)
// cerr<<v<<" ";
//cerr<<"\n";
answer(C,X,Y);
return;
}
Compilation message (stderr)
doll.cpp: In function 'void build_tree(int, int, int, int)':
doll.cpp:37:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(j=0;j<B[0].size();j++)
| ~^~~~~~~~~~~~
doll.cpp:39:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(j=0;j<B[1].size();j++)
| ~^~~~~~~~~~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:62:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for(int i=0;i<A.size()-1;i++)
| ~^~~~~~~~~~~
doll.cpp:66:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
66 | for(pot=1;2*pot<A.size();pot*=2);
| ~~~~~^~~~~~~~~
# | 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... |