#include "doll.h"
using namespace std;
int unneeded,CC,mp[1<<18];
vector<int>a,b;
int create(int l,int r){
if(unneeded>r-l)
return unneeded-=r-l+1,-1;
if(l==r) return l;
int k=--CC;
a.push_back(0);
b.push_back(0);
a[-k-1]=create(l,l+r>>1);
b[-k-1]=create(l+r+2>>1,r);
return k;
}
vector<int> a_order(int n,int sz,bool ok=1){
if(n==-1&&ok) return vector<int>(sz,-1);
if(n>0) return {n};
vector<int>A=a_order(a[-n-1],sz/2),B=a_order(b[-n-1],sz/2),C;
for(int i=0;i<A.size();i++)
C.push_back(A[i]),C.push_back(B[i]);
return C;
}
void create_circuit(int M, vector<int> A) {
A.push_back(0);
int N = A.size(),c=0;
int k=1<<31-__builtin_clz(2*N-1);
unneeded=k-N;
vector<int>C(M+1,-1),s=a_order(create(1,k),k,0);
for(auto i:s)
if(i>0)
mp[i]=A[c++];
for(auto &i:a)
if(i>0)i=mp[i];
for(auto &i:b)
if(i>0)i=mp[i];
answer(C,a,b);
}
Compilation message
doll.cpp: In function 'int create(int, int)':
doll.cpp:12:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
12 | a[-k-1]=create(l,l+r>>1);
| ~^~
doll.cpp:13:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
13 | b[-k-1]=create(l+r+2>>1,r);
| ~~~^~
doll.cpp: In function 'std::vector<int> a_order(int, int, bool)':
doll.cpp:20:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
20 | for(int i=0;i<A.size();i++)
| ~^~~~~~~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:27:16: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
27 | int k=1<<31-__builtin_clz(2*N-1);
| ~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
22 ms |
5252 KB |
Output is correct |
3 |
Correct |
22 ms |
5020 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
5 ms |
1460 KB |
Output is correct |
6 |
Correct |
32 ms |
7228 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
22 ms |
5252 KB |
Output is correct |
3 |
Correct |
22 ms |
5020 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
5 ms |
1460 KB |
Output is correct |
6 |
Correct |
32 ms |
7228 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
39 ms |
8388 KB |
Output is correct |
9 |
Correct |
47 ms |
8688 KB |
Output is correct |
10 |
Correct |
58 ms |
12472 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
22 ms |
5252 KB |
Output is correct |
3 |
Correct |
22 ms |
5020 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
5 ms |
1460 KB |
Output is correct |
6 |
Correct |
32 ms |
7228 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
39 ms |
8388 KB |
Output is correct |
9 |
Correct |
47 ms |
8688 KB |
Output is correct |
10 |
Correct |
58 ms |
12472 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
59 ms |
11864 KB |
Output is correct |
15 |
Correct |
51 ms |
7660 KB |
Output is correct |
16 |
Correct |
54 ms |
11360 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
57 ms |
12120 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
428 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
37 ms |
7400 KB |
Output is correct |
3 |
Correct |
33 ms |
7420 KB |
Output is correct |
4 |
Correct |
52 ms |
10100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
37 ms |
7400 KB |
Output is correct |
3 |
Correct |
33 ms |
7420 KB |
Output is correct |
4 |
Correct |
52 ms |
10100 KB |
Output is correct |
5 |
Correct |
60 ms |
11356 KB |
Output is correct |
6 |
Correct |
59 ms |
11132 KB |
Output is correct |
7 |
Correct |
55 ms |
11068 KB |
Output is correct |
8 |
Correct |
59 ms |
10840 KB |
Output is correct |
9 |
Correct |
36 ms |
7412 KB |
Output is correct |
10 |
Correct |
54 ms |
10848 KB |
Output is correct |
11 |
Correct |
53 ms |
10648 KB |
Output is correct |
12 |
Correct |
39 ms |
7428 KB |
Output is correct |
13 |
Correct |
40 ms |
7660 KB |
Output is correct |
14 |
Correct |
38 ms |
7744 KB |
Output is correct |
15 |
Correct |
37 ms |
7668 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
34 ms |
7936 KB |
Output is correct |
18 |
Correct |
36 ms |
7412 KB |
Output is correct |
19 |
Correct |
37 ms |
7412 KB |
Output is correct |
20 |
Correct |
55 ms |
10844 KB |
Output is correct |
21 |
Correct |
55 ms |
10588 KB |
Output is correct |
22 |
Correct |
53 ms |
10532 KB |
Output is correct |