#include "doll.h"
#include <cstdio>
#include <cassert>
#include <vector>
#include <algorithm>
const int MN = 3e5;
int S;
std::vector<int> X, Y;
bool root[MN], state[MN];
int dfs(int l, int r, int ql)
{
int n=++S; X.push_back(1), Y.push_back(1);
if(r-l>2)
{
int m=l+(r-l)/2;
if(ql < m) X[n-1] = dfs(l, m, ql);
Y[n-1] = dfs(m, r, ql);
}
else
root[n]=1;
return n;
}
void create_circuit(int M, std::vector<int> A) {
X.reserve(MN);
Y.reserve(MN);
int N = A.size();
std::vector<int> C(M + 1);
C[0]=A[0];
if(N==1)
{
C[C[0]]=0;
answer(C, X, Y);
return;
}
for(int i=1;i<=M;++i)
C[i]=-1;
//for(auto x:A) printf("%d ", x); printf("\n");
std::rotate(A.begin(), A.begin()+1, A.end());
A.back()=0;
if(A.size()&1)
A.insert(A.begin(), -1);
//for(auto x:A) printf("%d ", x); printf("\n");
int d = 31 - __builtin_clz((int)A.size()-1);
assert((1<<d+1) >= A.size() && A.size() > (1<<d));
int top;
top = dfs(0, 1<<d+1, (1<<d+1)-A.size());
for(int& x:X) x*=-1;
for(int& x:Y) x*=-1;
int ctr=0;
int n=-top;
for(;n != 0;)
{
//printf("ideal: %d\n", n);
if(n > 0)
n = -top;
else if(root[-n])
{
state[-n] ^= 1;
assert(ctr < A.size());
n = (state[-n] ? X[-n-1] : Y[-n-1]) = A[ctr++];
}
else
{
state[-n] ^= 1;
n = state[-n] ? X[-n-1] : Y[-n-1];
}
}
//printf("%d %lu\n", ctr, A.size());
assert(ctr == A.size());
answer(C, X, Y);
}
Compilation message
In file included from /usr/include/c++/10/cassert:44,
from doll.cpp:3:
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:52:14: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
52 | assert((1<<d+1) >= A.size() && A.size() > (1<<d));
| ~^~
doll.cpp:52:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
52 | assert((1<<d+1) >= A.size() && A.size() > (1<<d));
| ~~~~~~~~~^~~~~~~~~~~
doll.cpp:52:42: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
52 | assert((1<<d+1) >= A.size() && A.size() > (1<<d));
| ~~~~~~~~~^~~~~~~~
doll.cpp:55:19: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
55 | top = dfs(0, 1<<d+1, (1<<d+1)-A.size());
| ~^~
doll.cpp:55:28: warning: suggest parentheses around '+' inside '<<' [-Wparentheses]
55 | top = dfs(0, 1<<d+1, (1<<d+1)-A.size());
| ~^~
In file included from /usr/include/c++/10/cassert:44,
from doll.cpp:3:
doll.cpp:69:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | assert(ctr < A.size());
| ~~~~^~~~~~~~~~
doll.cpp:79:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
79 | assert(ctr == A.size());
| ~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
54 ms |
3656 KB |
Output is correct |
3 |
Correct |
43 ms |
3696 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
12 ms |
1484 KB |
Output is correct |
6 |
Correct |
66 ms |
4760 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
54 ms |
3656 KB |
Output is correct |
3 |
Correct |
43 ms |
3696 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
12 ms |
1484 KB |
Output is correct |
6 |
Correct |
66 ms |
4760 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
82 ms |
5436 KB |
Output is correct |
9 |
Correct |
92 ms |
6828 KB |
Output is correct |
10 |
Correct |
129 ms |
8108 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
54 ms |
3656 KB |
Output is correct |
3 |
Correct |
43 ms |
3696 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
12 ms |
1484 KB |
Output is correct |
6 |
Correct |
66 ms |
4760 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
82 ms |
5436 KB |
Output is correct |
9 |
Correct |
92 ms |
6828 KB |
Output is correct |
10 |
Correct |
129 ms |
8108 KB |
Output is correct |
11 |
Correct |
0 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
0 ms |
204 KB |
Output is correct |
14 |
Correct |
124 ms |
9184 KB |
Output is correct |
15 |
Correct |
80 ms |
5956 KB |
Output is correct |
16 |
Correct |
124 ms |
9068 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
125 ms |
11152 KB |
Output is correct |
21 |
Correct |
1 ms |
288 KB |
Output is correct |
22 |
Correct |
0 ms |
292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
0 ms |
204 KB |
Output is correct |
5 |
Correct |
0 ms |
204 KB |
Output is correct |
6 |
Correct |
0 ms |
204 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
0 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
75 ms |
4636 KB |
Output is correct |
3 |
Correct |
76 ms |
5280 KB |
Output is correct |
4 |
Correct |
126 ms |
6884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
75 ms |
4636 KB |
Output is correct |
3 |
Correct |
76 ms |
5280 KB |
Output is correct |
4 |
Correct |
126 ms |
6884 KB |
Output is correct |
5 |
Correct |
121 ms |
8876 KB |
Output is correct |
6 |
Correct |
128 ms |
9044 KB |
Output is correct |
7 |
Correct |
125 ms |
8980 KB |
Output is correct |
8 |
Correct |
121 ms |
8732 KB |
Output is correct |
9 |
Correct |
75 ms |
5700 KB |
Output is correct |
10 |
Correct |
136 ms |
8556 KB |
Output is correct |
11 |
Correct |
123 ms |
8388 KB |
Output is correct |
12 |
Correct |
76 ms |
6484 KB |
Output is correct |
13 |
Correct |
78 ms |
5816 KB |
Output is correct |
14 |
Correct |
79 ms |
6980 KB |
Output is correct |
15 |
Correct |
85 ms |
7104 KB |
Output is correct |
16 |
Correct |
2 ms |
460 KB |
Output is correct |
17 |
Correct |
74 ms |
6524 KB |
Output is correct |
18 |
Correct |
75 ms |
5584 KB |
Output is correct |
19 |
Correct |
78 ms |
6488 KB |
Output is correct |
20 |
Correct |
117 ms |
10104 KB |
Output is correct |
21 |
Correct |
116 ms |
8388 KB |
Output is correct |
22 |
Correct |
114 ms |
8388 KB |
Output is correct |