#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;
int high;
const int maxn = 8e5+5;
int L[maxn], R[maxn];
vector<int> all, matter;
void build(int cur, int bit, int dep, int to)
{
// printf("%d ", cur);
if(dep == high)
{
if(bit&1) R[cur] = -to;
else L[cur] = -to;
return;
}
if(bit&(1<<(high-dep)))
{
R[cur] = cur*2+1;
build(cur*2+1, bit, dep+1, to);
}
else
{
L[cur] = cur*2;
build(cur*2, bit, dep+1, to);
}
}
bool cmp(int a, int b)
{
for(int i = 0; i<= high; i++)
{
int x = a & (1<<i);
int y = b & (1<<i);
if(x != y) return x< y;
}
}
void create_circuit(int m, vector<int> A)
{
memset(L, 31, sizeof L);
memset(R, 31, sizeof R);
int n = A.size();
int leaves = n-1;
int sig = -1;
for(int i = 20; i>= 0; i--)
{
if((1<<i) & leaves)
{
sig = i+1;
break;
}
}
high = sig;
for(int i = 0; i< n-1; i++) all.pb(i);
all.pb((1<<high)-1);
sort(all.begin(), all.end(), cmp);
// printf("%d\n", high);
for(int i = 0; i< n; i++)
{
// printf("insert %d\n", all[i]);
build(1, all[i], 1, i< n-1?A[i+1]:0);
// printf("\n");
}
for(int i = 1; i< (1<<high); i++)
{
if(L[i]> 0 && L[i] != 522133279) matter.pb(L[i]);
if(R[i]> 0 && R[i] != 522133279) matter.pb(R[i]);
}
matter.pb(1);
sort(matter.begin(), matter.end());
// printf("%d\n", matter.size());
vector<int> ansx, ansy;
ansx.resize(matter.size());
ansy.resize(matter.size());
vector<int> res(m+1, -1);
res[0] = A[0];
for(int i = 0; i< (int) matter.size(); i++)
{
int sw = matter[i];
// printf("%d: %d %d\n", sw, L[sw], R[sw]);
if(L[sw]> 0)
{
if(L[sw] == 522133279) ansx[i] = -1;
else ansx[i] = -(lower_bound(matter.begin(), matter.end(), L[sw])-matter.begin()+1);
}
else
{
ansx[i] = -L[sw];
}
if(R[sw]> 0)
{
if(R[sw] == 522133279) ansy[i] = -1;
else ansy[i] = -(lower_bound(matter.begin(), matter.end(), R[sw])-matter.begin()+1);
}
else
{
ansy[i] = -R[sw];
}
// printf("res %d %d\n", ansx[i], ansy[i]);
}
answer(res, ansx, ansy);
}
Compilation message
doll.cpp: In function 'bool cmp(int, int)':
doll.cpp:46:1: warning: control reaches end of non-void function [-Wreturn-type]
46 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
6476 KB |
Output is correct |
2 |
Correct |
75 ms |
10416 KB |
Output is correct |
3 |
Correct |
75 ms |
10668 KB |
Output is correct |
4 |
Correct |
4 ms |
6476 KB |
Output is correct |
5 |
Correct |
16 ms |
7744 KB |
Output is correct |
6 |
Incorrect |
108 ms |
11696 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
6476 KB |
Output is correct |
2 |
Correct |
75 ms |
10416 KB |
Output is correct |
3 |
Correct |
75 ms |
10668 KB |
Output is correct |
4 |
Correct |
4 ms |
6476 KB |
Output is correct |
5 |
Correct |
16 ms |
7744 KB |
Output is correct |
6 |
Incorrect |
108 ms |
11696 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
6476 KB |
Output is correct |
2 |
Correct |
75 ms |
10416 KB |
Output is correct |
3 |
Correct |
75 ms |
10668 KB |
Output is correct |
4 |
Correct |
4 ms |
6476 KB |
Output is correct |
5 |
Correct |
16 ms |
7744 KB |
Output is correct |
6 |
Incorrect |
108 ms |
11696 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
6476 KB |
Output is correct |
2 |
Correct |
6 ms |
6476 KB |
Output is correct |
3 |
Correct |
5 ms |
6452 KB |
Output is correct |
4 |
Correct |
5 ms |
6520 KB |
Output is correct |
5 |
Correct |
4 ms |
6476 KB |
Output is correct |
6 |
Correct |
4 ms |
6476 KB |
Output is correct |
7 |
Correct |
5 ms |
6476 KB |
Output is correct |
8 |
Correct |
4 ms |
6436 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
6476 KB |
Output is correct |
2 |
Correct |
121 ms |
11820 KB |
Output is correct |
3 |
Correct |
122 ms |
12344 KB |
Output is correct |
4 |
Partially correct |
183 ms |
14412 KB |
Output is partially correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
6476 KB |
Output is correct |
2 |
Correct |
121 ms |
11820 KB |
Output is correct |
3 |
Correct |
122 ms |
12344 KB |
Output is correct |
4 |
Partially correct |
183 ms |
14412 KB |
Output is partially correct |
5 |
Partially correct |
193 ms |
14776 KB |
Output is partially correct |
6 |
Partially correct |
193 ms |
14660 KB |
Output is partially correct |
7 |
Partially correct |
199 ms |
14648 KB |
Output is partially correct |
8 |
Partially correct |
211 ms |
14432 KB |
Output is partially correct |
9 |
Partially correct |
117 ms |
12332 KB |
Output is partially correct |
10 |
Partially correct |
203 ms |
14516 KB |
Output is partially correct |
11 |
Partially correct |
189 ms |
14520 KB |
Output is partially correct |
12 |
Correct |
124 ms |
12600 KB |
Output is correct |
13 |
Correct |
126 ms |
11816 KB |
Output is correct |
14 |
Correct |
133 ms |
13088 KB |
Output is correct |
15 |
Correct |
128 ms |
13216 KB |
Output is correct |
16 |
Correct |
8 ms |
6764 KB |
Output is correct |
17 |
Correct |
124 ms |
11812 KB |
Output is correct |
18 |
Correct |
126 ms |
11828 KB |
Output is correct |
19 |
Correct |
127 ms |
12608 KB |
Output is correct |
20 |
Partially correct |
199 ms |
14520 KB |
Output is partially correct |
21 |
Partially correct |
195 ms |
14460 KB |
Output is partially correct |
22 |
Partially correct |
183 ms |
14420 KB |
Output is partially correct |