이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 // makes n+1 zero
}
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) { // removes n zero
int& nx = (state[-pos] ? y[-pos] : x[-pos]);
state[-pos] ^= 1;
if (nx == 0) {
nx = v;
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);
while(p <= n) p *= 2;
x = VI(2*p, 0);
y = VI(2*p, 0);
state = 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... |