G. Game Design

#include<bits/stdc++.h>
#define inf 1e7
#define ll long long 
#define int long long 
#define ull unsigned long long 
#define PI acos(-1.0)
#define PII pair<int,int>
using namespace std;
const int N = 1e5+7;
const int p = 998244353;
int k,num,pa[N],c[N];
void dfs(int fa,int w,int val){//父亲 任务 权值 
    int u = ++num;
//    cout<<"=== "<<u<<"  "<<fa<<"  "<<w<<"  "<<val<<"\n";
    pa[u] = fa;
    c[u] = val;
    w--;
    if(w == 0){
        return ;
    }
    int l = (int)sqrt(w);
    while(w%l!=0) l--;
    int r = w/l;
    dfs(u,l,val>>1ll);
    dfs(u,r,val>>1ll);
}
void solve(){
    num = 0;
    scanf("%lld",&k);
    if(k==1){
        printf("2\n1\n2 1\n");
        return ;
    }
    dfs(0,k,(1ll<<29));
    
    printf("%lld\n",num);
    for(int i=2;i<=num;++i){
        printf("%lld ",pa[i]);
    }
    printf("\n");
    for(int i=1;i<=num;++i){
        printf("%lld ",c[i]);
    }
}
signed main(){
    int t=1;
    //scanf("%lld",&t);
    for(int _=1;_<=t;++_){
        solve();
    }
    return 0;
}

 

上一篇:高斯消元-异或版


下一篇:P3857 [TJOI2008]彩灯