#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include "messy.h"
std::string initialize(int n, int l, int r) {
std::string s(n, '1');
for (int i = l; i <= r; i++)
s[i] = '0';
return s;
}
void insertions(int n, int l, int r) {
if (l == r)
return;
int m = (l + r) / 2;
std::string s = initialize(n, l, r);
for (int i = l; i <= m; i++) {
s[i] = '1';
add_element(s);
s[i] = '0';
}
insertions(n, l, m);
insertions(n, m + 1, r);
}
std::string initializeQuery(int n, std::vector<bool> &com) {
std::string s(n, '0');
for (int i = 0; i < n; i++) {
if (com[i])
s[i] = '1';
}
return s;
}
int findElement(int n, std::vector<bool> &inSet) {
for (int i = 0; i < n; i++)
if(inSet[i])
return i;
return -1;
}
void getPermutation(int n, int l, int r, std::vector<bool> &inSet, std::vector<bool> &outSet, std::vector<int> &ans) {
if (l == r) {
ans[l] = findElement(n, inSet);
return;
}
std::string s = initializeQuery(n, outSet);
std::vector<bool> inSetLeft(n, false), inSetRight(n, false);
std::vector<bool> outSetLeft, outSetRight;
outSetLeft = outSetRight = outSet;
int m = (l + r) / 2;
for (int i = 0; i < n; i++) {
if (s[i] == '0') {
s[i] = '1';
if (check_element(s)) {
inSetLeft[i] = true;
outSetRight[i] = true;
} else {
inSetRight[i] = true;
outSetLeft[i] = true;
}
s[i] = '0';
}
}
printSet(inSetLeft);
printSet(outSetLeft);
printSet(inSetRight);
printSet(outSetRight);
getPermutation(n, l, m, inSetLeft, outSetLeft, ans);
getPermutation(n, m + 1, r, inSetRight, outSetRight, ans);
}
std::vector<int> getAns(int n, std::vector<int> &preAns) {
std::vector<int> ans(n, 0);
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
if (preAns[j] == i) {
ans[i] = j;
break;
}
}
}
return ans;
}
std::vector<int> restore_permutation(int n, int w, int r) {
insertions(n, 0, n - 1);
std::vector<int> preAns(n);
std::vector<bool> inSet(n, true);
std::vector<bool> outSet(n, false);
compile_set();
getPermutation(n, 0, n - 1, inSet, outSet, preAns);
return getAns(n, preAns);
}
Compilation message
messy.cpp: In function 'void getPermutation(int, int, int, std::vector<bool>&, std::vector<bool>&, std::vector<int>&)':
messy.cpp:74:5: error: 'printSet' was not declared in this scope; did you mean 'inSet'?
74 | printSet(inSetLeft);
| ^~~~~~~~
| inSet