#include "messy.h"
#include <bits/stdc++.h>
using namespace std;
#define OPTM ios_base::sync_with_stdio(0); cin.tie(0);
#define INF int(1e9+7)
#define ln '\n'
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define FOR(i,s,n) for (int i = s; i < n; i++)
#define FORR(i,n,s) for (int i = n; i > s; i--)
#define FORX(u, arr) for (auto u : arr)
#define PB push_back
#define in(v,x) (v.find(x) != v.end())
#define F first
#define S second
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define UM unordered_map
#define US unordered_set
#define PQ priority_queue
#define ALL(v) v.begin(), v.end()
const ll LLINF = 1e18+1;
const int MAXN = 130, LOG = 8;
int p[MAXN], rp[MAXN], lg[MAXN];
vector<int> a[LOG][MAXN];
string orig = "";
int n;
vector<int> sub2() {
string s = "";
FOR(i,0,n) s.PB('0');
FOR(i,0,n) {
s[i] = '1';
add_element(s);
}
compile_set();
string t = "";
FOR(i,0,n) t.PB('0');
vector<int> p(n,-1);
vector<int> v;
FOR(i,0,n) v.PB(i);
FOR(i,0,n) {
mt19937 rng(time(0));
shuffle(ALL(v),rng);
FOR(j,0,n) {
if (t[v[j]] == '1') continue;
t[v[j]] = '1';
if (check_element(t)) {
p[v[j]] = i;
break;
}
else t[v[j]] = '0';
}
}
return p;
}
void solve(int l, int r) {
int len = r-l+1;
int idx = l/len;
string s = orig;
FORR(j,lg[n],-1) {
int cl = 0, cr = (1<<j)-1;
FOR(i,0,(1<<(lg[n]-j))) {
if (cr < l || cl > r) {
FORX(u,a[j][i]) s[u] = '1';
}
cl += (1<<j);
cr += (1<<j);
}
}
US<int> st;
FORX(u,a[lg[len]][idx]) st.insert(u);
// cout << l << " " << r << ": ";
// FORX(u,st) {
// cout << u << " ";
// }
// cout << ln;
FOR(i,0,n) {
if (s[i] == '1') continue;
s[i] = '1';
bool ans = check_element(s);
s[i] = '0';
if (ans) {
a[lg[len]-1][idx*2].PB(i);
st.erase(i);
}
}
FORX(u,st) {
//cout << "e: " << u << " ";
a[lg[len]-1][idx*2+1].PB(u);
}
//cout << ln;
if (len == 2) return;
int mid = (l+r)/2;
solve(l,mid);
solve(mid+1,r);
}
vector<int> sub3() {
FOR(i,0,n) orig.PB('0');
FOR(i,1,LOG) lg[1<<i] = lg[1<<(i-1)]+1;
FOR(i,0,n) a[lg[n]][0].PB(i);
FOR(k,1,lg[n]+1) {
for (int j = 0; j < n; j += (1<<k)) {
string s = orig;
FOR(i,0,n) {
if (i < j || i >= j+(1<<k)) s[i] = '1';
}
FOR(i,j,j+(1<<(k-1))) {
s[i] = '1';
add_element(s);
// cout << s << " ";
s[i] = '0';
}
}
}
cout << ln;
// FOR(i,0,n/2) {
// string s = orig;
// s[i] = '1';
// add_element(s);
// cout << s << " ";
// }
compile_set();
// vector<bool> z(n,0);
// FOR(i,0,n) {
// string s = orig;
// s[i] = '1';
// if (check_element(s)) z[i] = 1;
// }
solve(0,n-1);
vector<int> res(n,-1);
FOR(i,0,n) {
// FORX(u,a[0][i]) cout << u << " ";
// cout << ln;
int pos = a[0][i][0];
res[pos] = i;
}
// FOR(i,0,lg[n]+1) {
// int nl = 0, nr = (1<<i)-1;
// FOR(j,0,8) {
// cout << nl << " " << nr << ": ";
// FORX(u,a[i][j]) cout << u << " ";
// cout << ln;
// nl += (1<<i);
// nr += (1<<i);
// }
// }
return res;
}
std::vector<int> restore_permutation(int N, int w, int r) {
n = N;
return sub3();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Wrong secret! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Wrong secret! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Wrong secret! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
Wrong secret! |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
468 KB |
Wrong secret! |
2 |
Halted |
0 ms |
0 KB |
- |