#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 n;
int lg[MAXN];
vector<int> a[LOG][MAXN];
string orig = "";
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);
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) a[lg[len]-1][idx*2+1].PB(u);
if (len == 2) return;
int mid = (l+r)/2;
solve(l,mid);
solve(mid+1,r);
}
std::vector<int> restore_permutation(int N, int w, int r) {
n = N;
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);
s[i] = '0';
}
}
}
compile_set();
solve(0,n-1);
vector<int> res(n,-1);
FOR(i,0,n) res[a[0][i][0]] = i;
return res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
n = 8 |
2 |
Correct |
0 ms |
212 KB |
n = 8 |
3 |
Correct |
0 ms |
212 KB |
n = 8 |
4 |
Correct |
0 ms |
212 KB |
n = 8 |
5 |
Correct |
0 ms |
212 KB |
n = 8 |
6 |
Correct |
0 ms |
212 KB |
n = 8 |
7 |
Correct |
0 ms |
212 KB |
n = 8 |
8 |
Correct |
0 ms |
212 KB |
n = 8 |
9 |
Correct |
0 ms |
212 KB |
n = 8 |
10 |
Correct |
0 ms |
212 KB |
n = 8 |
11 |
Correct |
0 ms |
212 KB |
n = 8 |
12 |
Correct |
0 ms |
212 KB |
n = 8 |
13 |
Correct |
0 ms |
212 KB |
n = 8 |
14 |
Correct |
0 ms |
212 KB |
n = 8 |
15 |
Correct |
0 ms |
212 KB |
n = 8 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
n = 32 |
2 |
Correct |
0 ms |
340 KB |
n = 32 |
3 |
Correct |
1 ms |
340 KB |
n = 32 |
4 |
Correct |
0 ms |
340 KB |
n = 32 |
5 |
Correct |
1 ms |
340 KB |
n = 32 |
6 |
Correct |
0 ms |
340 KB |
n = 32 |
7 |
Correct |
1 ms |
340 KB |
n = 32 |
8 |
Correct |
1 ms |
340 KB |
n = 32 |
9 |
Correct |
0 ms |
340 KB |
n = 32 |
10 |
Correct |
0 ms |
340 KB |
n = 32 |
11 |
Correct |
0 ms |
340 KB |
n = 32 |
12 |
Correct |
0 ms |
340 KB |
n = 32 |
13 |
Correct |
1 ms |
340 KB |
n = 32 |
14 |
Correct |
1 ms |
340 KB |
n = 32 |
15 |
Correct |
0 ms |
340 KB |
n = 32 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
n = 32 |
2 |
Correct |
1 ms |
340 KB |
n = 32 |
3 |
Correct |
0 ms |
340 KB |
n = 32 |
4 |
Correct |
1 ms |
212 KB |
n = 32 |
5 |
Correct |
0 ms |
340 KB |
n = 32 |
6 |
Correct |
0 ms |
340 KB |
n = 32 |
7 |
Correct |
0 ms |
340 KB |
n = 32 |
8 |
Correct |
0 ms |
340 KB |
n = 32 |
9 |
Correct |
0 ms |
340 KB |
n = 32 |
10 |
Correct |
1 ms |
340 KB |
n = 32 |
11 |
Correct |
0 ms |
340 KB |
n = 32 |
12 |
Correct |
0 ms |
340 KB |
n = 32 |
13 |
Correct |
0 ms |
340 KB |
n = 32 |
14 |
Correct |
0 ms |
340 KB |
n = 32 |
15 |
Correct |
0 ms |
340 KB |
n = 32 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
n = 128 |
2 |
Correct |
1 ms |
468 KB |
n = 128 |
3 |
Correct |
1 ms |
468 KB |
n = 128 |
4 |
Correct |
1 ms |
468 KB |
n = 128 |
5 |
Correct |
1 ms |
468 KB |
n = 128 |
6 |
Correct |
1 ms |
468 KB |
n = 128 |
7 |
Correct |
1 ms |
468 KB |
n = 128 |
8 |
Correct |
1 ms |
468 KB |
n = 128 |
9 |
Correct |
1 ms |
468 KB |
n = 128 |
10 |
Correct |
1 ms |
468 KB |
n = 128 |
11 |
Correct |
2 ms |
468 KB |
n = 128 |
12 |
Correct |
1 ms |
596 KB |
n = 128 |
13 |
Correct |
1 ms |
468 KB |
n = 128 |
14 |
Correct |
2 ms |
468 KB |
n = 128 |
15 |
Correct |
1 ms |
468 KB |
n = 128 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
468 KB |
n = 128 |
2 |
Correct |
1 ms |
468 KB |
n = 128 |
3 |
Correct |
1 ms |
468 KB |
n = 128 |
4 |
Correct |
1 ms |
468 KB |
n = 128 |
5 |
Correct |
2 ms |
468 KB |
n = 128 |
6 |
Correct |
1 ms |
468 KB |
n = 128 |
7 |
Correct |
1 ms |
468 KB |
n = 128 |
8 |
Correct |
1 ms |
468 KB |
n = 128 |
9 |
Correct |
1 ms |
468 KB |
n = 128 |
10 |
Correct |
1 ms |
468 KB |
n = 128 |
11 |
Correct |
1 ms |
468 KB |
n = 128 |
12 |
Correct |
1 ms |
468 KB |
n = 128 |
13 |
Correct |
1 ms |
468 KB |
n = 128 |
14 |
Correct |
1 ms |
468 KB |
n = 128 |
15 |
Correct |
1 ms |
468 KB |
n = 128 |