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 "bits/stdc++.h"
#include "doll.h"
using namespace std;
const int maxn = 5e5 + 10;
vector <int> g[maxn];
int l[maxn], r[maxn];
bool leaf[maxn];
int to[maxn];
int node = 0;
int create(int b, int e, vector <int> &order) {
int cur = ++node;
if(b == e) {
leaf[cur] = true;
order.push_back(cur);
order.push_back(cur);
return cur;
}
int mid = (b + e) >> 1;
vector <int> left, right;
l[cur] = create(b, mid, left);
r[cur] = create(mid + 1, e, right);
for(int i = 0; i < left.size(); i++) {
order.push_back(left[i]);
order.push_back(right[i]);
}
return cur;
}
void getEdges(int root, vector <int> v) {
if(v.empty()) return ;
int sz = 1;
while(sz * 2 < v.size()) sz *= 2;
vector <int> order;
to[root] = -create(1, sz, order);
set <int> cont;
int pt = 0;
for(int i = 0; i < order.size(); i++) {
if(cont.count(order[i])) {
if(i >= order.size() - v.size()) {
r[order[i]] = v[pt++];
} else {
r[order[i]] = to[root];
}
} else {
if(i >= order.size() - v.size()) {
l[order[i]] = v[pt++];
} else {
l[order[i]] = to[root];
}
}
cont.insert(order[i]);
}
}
void create_circuit(int M, std::vector<int> A) {
int N = A.size();
A.insert(A.end(), 0);
getEdges(0, A);
vector <int> C(M + 1);
vector <int> X (node), Y (node);
for(int i = 0; i <= M; i++) {
C[i] = to[0];
}
for(int i = 1; i <= node; i++) {
if(leaf[i]) {
X[i - 1] = l[i];
Y[i - 1] = r[i];
} else {
X[i - 1] = -l[i];
Y[i - 1] = -r[i];
}
}
answer(C, X, Y);
}
Compilation message (stderr)
doll.cpp: In function 'int create(int, int, std::vector<int>&)':
doll.cpp:23:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for(int i = 0; i < left.size(); i++) {
| ~~^~~~~~~~~~~~~
doll.cpp: In function 'void getEdges(int, std::vector<int>)':
doll.cpp:32:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | while(sz * 2 < v.size()) sz *= 2;
| ~~~~~~~^~~~~~~~~~
doll.cpp:37:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for(int i = 0; i < order.size(); i++) {
| ~~^~~~~~~~~~~~~~
doll.cpp:39:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | if(i >= order.size() - v.size()) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
doll.cpp:45:12: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | if(i >= order.size() - v.size()) {
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:56:7: warning: unused variable 'N' [-Wunused-variable]
56 | int N = A.size();
| ^
# | 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... |