제출 #417335

#제출 시각아이디문제언어결과실행 시간메모리
417335balbit자동 인형 (IOI18_doll)C++14
100 / 100
159 ms20884 KiB
#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
//#define BALBIT
#define ll long long
#define pii pair<int, int>
#define pb push_back
#define f first
#define s second

#define REP(i,n) for (int i = 0; i<n; ++i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)

#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()


#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<"- "<<#__VA_ARGS__<<": ", _do(__VA_ARGS__)

template<typename T> void _do(T && x) { cerr<<x<<endl;}
template<typename T, typename ...S> void _do(T && x, S &&...y) {cerr<<x<<", "; _do(y...);}
#else
#define bug(...)

#endif // BALBIT

const int maxn = 2e5+5;

vector<int> go[maxn];

int IT = 0; // keep indexes positive until returning

vector<int> X,Y;
vector<int> sw;
bool st[maxn*4];
bool del[maxn*4];
int par[maxn*4];
bool isx[maxn*4];

//int add(int x=0, int y=0) {
//    X.pb(x); Y.pb(y);
//    return ++IT;
//}

const int inf = 1000000000;

int build(int sz, int bk, int lft) {
    bug(sz,bk,lft);
    if(sz == 0) return bk;
    if (lft == 0) {
//        assert(sz == 1);
        return inf;
    }
    int me = ++IT;
    int bg = min(sz,(1<<(lft-1)));
    X[me] = build(sz-bg, bk, lft-1);
    Y[me] = build(bg, bk, lft-1);
    return -me;
}

void create_circuit(int n, std::vector<int> A) {
    bug("HI");
    X.pb(0); Y.pb(0);
    A.pb(0);
    sw.resize(n+1);
    sw[0] = A[0];
    A.erase(A.begin());
    int m = SZ(A);
    REP(i, m-1) {
        go[A[i]].pb(A[i+1]);
    }
    X.resize(m*2+1); Y.resize(m*2+1);
    int pw = 0;
    while ((1<<pw) < m) ++pw;
    int rt = build(m, -1, pw);
    for (int i = 1; i<=n; ++i) sw[i] = rt==-1?rt:0;
//    assert(rt == -1);
    if (rt == -1) REP(j, m) {
        int at = 1;
        while (1) {
            int &to = st[at]?Y[at]:X[at];
            bug(at, to);
            st[at] ^= 1;
            if (to == inf) {
                to = A[j];
                break;
            }else{
                at = -(to);
            }
        }
    }


    X.erase(X.begin()); Y.erase(Y.begin());
    X.resize(IT); Y.resize(IT);
    answer(sw,X,Y);
}


/*
5 9
1 2 1 3 1 4 1 5 1
*/
#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...