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;
#define dbgv(v) cout<<#v<<" = "; f(i,0,v.size()) cout<<v[i]<<" "; cout<<endl
#define dbga(a,x,y) cout<<#a<<" = "; f(i,x,y) cout<<a[i]<<" "; cout<<endl
#define erorp(x) cout<<#x<<"={"<<x.F<<" , "<<x.S<<"}"<<endl
#define eror(x) cout<<#x<<'='<<(x)<<endl
#define f_(i,a,b) for(int i=a;i>=b;i--)
#define f(i,a,b) for(int i=a;i<b;i++)
#define nb(x) __builtin_popcount(x)
#define all(v) v.begin(),v.end()
#define bit(n,k) (((n)>>(k))&1)
#define Add(x,y) x=(x+y)%mod
#define maxm(a,b) a=max(a,b)
#define minm(a,b) a=min(a,b)
#define lst(x) x[x.size()-1]
#define sz(x) int(x.size())
#define mp make_pair
#define ll long long
#define pb push_back
#define S second
#define F first
const int N=2e5+99;
int n,m,lg,cnt;
vector<int> A,B;
int g[N][2];
void solve(int now,int ted){
if(ted==2) return ;
g[now][0]=++cnt;
solve(cnt,ted/2);
g[now][1]=++cnt;
solve(cnt,ted/2);
}
void create_circuit(int _n,vector<int> _A) {
f(i,0,N) g[i][0]=g[i][1]=N;
n=_n,m=_A.size(),A=_A;
f(i,0,30) if((1<<i)>m){
lg=i;
break;
}
cnt=lg;
f(i,1,lg){
if(n&(1<<(lg-i))){
g[i][0]=++cnt;
solve(cnt,(1<<(lg-i)));
}
else{
g[i][0]=1;
}
g[i][1]=i+1;
}
if(bit(n,0)==0){
g[lg][0]=1;
}
g[lg][1]=0;
int now=1,p=0,prt=0;
while(now!=0){
prt++;
//eror(now);
if(now<0){
now=1;
continue ;
}
if(g[now][0]==N){
g[now][0]=-A[p]; p++;
}
swap(g[now][0],g[now][1]);
now=g[now][1];
if(prt>200) break;
}
vector<int> adj(n+1,-1);
vector<int> X,Y;
f(i,1,cnt+1) X.pb(-g[i][0]),Y.pb(-g[i][1]);
//dbgv(adj);
//dbgv(X);
//dbgv(Y);
answer(adj,X,Y);
}
/*
2 2
1 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... |