Submission #525211

#TimeUsernameProblemLanguageResultExecution timeMemory
525211qwerasdfzxclMechanical Doll (IOI18_doll)C++14
84 / 100
134 ms262148 KiB
#include "doll.h"
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
vector<int> C, X, Y, Q[100100];

int l;
vector<int> nxt;

void build_tree(int i, int root, int H, int val, bool on){
    if (on && (val&(1<<H))) X[i] = -root;
    else if (H){
        X.push_back(1e9);
        Y.push_back(1e9);
        X[i] = -(int)X.size();
        build_tree((int)X.size()-1, root, H-1, val, 0);
    }

    if (H){
        X.push_back(1e9);
        Y.push_back(1e9);
        Y[i] = -(int)X.size();
        build_tree((int)X.size()-1, root, H-1, val, on&1);
    }
}

bool ON[400400];
void getidx(int i){
    ON[i] ^= 1;
    if (ON[i]){
        if (X[i]==1e9) X[i] = nxt[l++];
        else getidx(-X[i]-1);
    }
    else{
        if (Y[i]==1e9) Y[i] = nxt[l++];
        else getidx(-Y[i]-1);
    }
}

void create_circuit(int M, std::vector<int> A) {
    int n = A.size();
    C.resize(M+1, -1);
    A.push_back(0);
    C[0] = A[0];
    X.push_back(1e9); Y.push_back(1e9);

    int t = 1, h = 0, R = (int)X.size()-1;
    for (;t<n;t<<=1, h++);

    build_tree(R, R+1, h-1, t-n, 1);
    for (int i=1;i<(int)A.size();i++) nxt.push_back(A[i]);
    while(l<(int)nxt.size()) getidx(R);


    answer(C, X, Y);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...