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>
#define sz(x) (int)x.size()
#define ALL(x) x.begin(), x.end()
#define pb push_back
#define ff first
#define ss second
using namespace std;
using VI = vector <int>;
using PII = pair <int, int>;
int n, m, p = 1;
VI c, x, y, state;
int switchNo = 1;
bool vis;
int generate(int l, int r) {
if (l == r) {
return (r+n < p ? -1 : 0); // not switch
}
int mid = (l+r)>>1, curNode = switchNo++;
x[curNode] = generate(l, mid);
y[curNode] = generate(mid+1, r);
// cout << curNode << ": " << x[curNode] << ',' << y[curNode] << " -> " << l << ' ' << r << '\n';
return -curNode;
}
bool last;
void addPos(int pos, int v) {
int& nx = (state[-pos] ? y[-pos] : x[-pos]);
state[-pos] ^= 1;
// cout << pos << " " << v << " TO " << nx << '\n';
if (nx == 0) {
nx = v;
// cout <<" HERE: " << pos << " -> " << v << '\n';
last = v;
c[v] = -1;
return;
}
return addPos(nx, v);
}
void create_circuit(int M, vector<int> nums) {
m = M;
n = sz(nums);
c = VI(m+1, 0);
state = VI(switchNo+5, 0);
while(p <= n) p *= 2;
x = VI(2*p, 0);
y = VI(2*p, 0);
generate(1, p);
c[0] = -1;
for (int i = 0; i < n; i++) {
addPos(-1, nums[i]);
}
x.resize(switchNo);
y.resize(switchNo);
reverse(ALL(x));
reverse(ALL(y));
x.pop_back();
y.pop_back();
reverse(ALL(x));
reverse(ALL(y));
// cout << "C: ";
// for (int i = 0; i < m; i++) cout << c[i] << " \n"[i==m-1];
// cout << "XY: ";
// for (int i = 0; i < sz(x); i++) cout << x[i] << ',' << y[i] << " \n"[i==sz(x)-1];
answer(c, x, y);
}
# | 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... |