이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "doll.h"
#define pb push_back
using namespace std;
const int maxn = 300100;
int n, m;
int N, br; // N is the first power of two greater than n
int x[maxn], y[maxn];
int build_tree(int l, int r, int cnt) {
int ind = br;
br++;
if(r == l + 1) {
//cout<<l<<", "<<r<<" - "<<cnt<<"\n";
if(cnt == 1) x[ind] = 1;
return ind;
}
//cout<<l<<" "<<r<<" -> "<<ind<<" "<<cnt<<"\n";
int tsize = r - l + 1;
int mid = tsize / 2;
if(cnt <= mid) {
// build recursively right subtree
// make left subtree go left
int midpoint = (l+r)/2;
x[ind] = 1;
y[ind] = build_tree(midpoint+1, r, cnt);
}
else {
// make all in right
// everything that is left put in left subtree
int midpoint = (l+r)/2;
y[ind] = build_tree(midpoint+1, r, mid);
x[ind] = build_tree(l, midpoint, cnt-mid);
}
return ind;
}
bool state[maxn];
int pntr_x[maxn];
int pntr_y[maxn];
void insert_point(int ind, int val, int l, int r) {
if(r == l + 1) {
// base case
if(!state[ind]) {
state[ind] = true;
if(x[ind] == 0) {
pntr_x[ind] = val;
}
else insert_point(x[ind], val, 0, N-1);
}
else {
state[ind] = false;
if(y[ind] == 0) {
pntr_y[ind] = val;
}
else insert_point(y[ind], val, 0, N-1);
}
return;
}
else {
state[ind] = !state[ind];
int mid = (l + r) / 2;
if(state[ind]) {
// left
if(x[ind] == 1) insert_point(x[ind], val, 0, N-1);
else insert_point(x[ind], val, l, mid);
}
else {
// right
if(y[ind] == -1) insert_point(y[ind], val, 0, N-1);
else insert_point(y[ind], val, mid+1, r);
}
}
}
void create_circuit(int M, std::vector<int> A) {
A.pb(0);
m = M; n = A.size();
vector<int>C(M+1);
for(int i=0;i<=M;i++) {
C[i] = -1;
}
N = 1;
while(N < n) {
N *= 2;
}
br = 1;
build_tree(0, N-1, n);
vector<int>X, Y;
for(int i=0;i<n;i++) {
insert_point(1, A[i], 0, N-1);
}
for(int i=1;i<br;i++) {
if(x[i] == 0) X.pb(pntr_x[i]);
else X.pb(-x[i]);
if(y[i] == 0) Y.pb(pntr_y[i]);
else Y.pb(-y[i]);
}
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... |