#include "doll.h"
#include <queue>
using namespace std;
int sw[(int)4e5][2];
int trig[(int)2e5];
void create_circuit(int M, vector<int> A) {
for(int i = 0;i <= M;i++){
trig[i] = -1;
}
int N = A.size();
int lgN = 0;
while((1 << lgN) <= N){
lgN++;
}
lgN--;
int last_switch = -(lgN + 1);
queue< pair<int,int> > switches;
for(int i = 0;i < lgN;i++){
sw[i + 1][1] = -(i + 2);
if((N >> (lgN - i)) & 1){
sw[i + 1][0] = --last_switch;
switches.push({last_switch,lgN - i - 1});
}
else{
sw[i + 1][0] = -1;
}
}
sw[lgN + 1][1] = 0;
if(N & 1){
sw[lgN + 1][0] = 0;
}
else{
sw[lgN + 1][0] = -1;
}
while(!switches.empty()){
int s = switches.front().first;
int lvl = switches.front().second;
switches.pop();
if(lvl != 0){
sw[-s][0] = --last_switch;
switches.push({last_switch,lvl - 1});
sw[-s][1] = --last_switch;
switches.push({last_switch,lvl - 1});
}
else{
sw[-s][0] = sw[-s][1] = 0;
}
}
int ind = 0;
int node = -1;
while(node != 0){
if(sw[-node][0] == 0){
if(ind == A.size()){
swap(sw[-node][0],sw[-node][1]);
node = 0;
continue;
}
sw[-node][0] = A[ind++];
swap(sw[-node][0],sw[-node][1]);
node = -1;
}
else{
swap(sw[-node][0],sw[-node][1]);
node = sw[-node][1];
}
}
vector<int> X(-last_switch),Y(-last_switch),C(M + 1);
for(int i = 0;i <= M;i++){
C[i] = trig[i];
}
for(int i = 0;i < -last_switch;i++){
X[i] = sw[i + 1][0];
Y[i] = sw[i + 1][1];
}
answer(C,X,Y);
}
Compilation message
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:69:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | if(ind == A.size()){
| ~~~~^~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
41 ms |
4688 KB |
Output is correct |
3 |
Correct |
38 ms |
4176 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
11 ms |
1868 KB |
Output is correct |
6 |
Correct |
60 ms |
6112 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
41 ms |
4688 KB |
Output is correct |
3 |
Correct |
38 ms |
4176 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
11 ms |
1868 KB |
Output is correct |
6 |
Correct |
60 ms |
6112 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
92 ms |
6956 KB |
Output is correct |
9 |
Correct |
81 ms |
7460 KB |
Output is correct |
10 |
Correct |
112 ms |
10152 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
41 ms |
4688 KB |
Output is correct |
3 |
Correct |
38 ms |
4176 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
11 ms |
1868 KB |
Output is correct |
6 |
Correct |
60 ms |
6112 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
92 ms |
6956 KB |
Output is correct |
9 |
Correct |
81 ms |
7460 KB |
Output is correct |
10 |
Correct |
112 ms |
10152 KB |
Output is correct |
11 |
Correct |
1 ms |
204 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
106 ms |
9684 KB |
Output is correct |
15 |
Correct |
68 ms |
6084 KB |
Output is correct |
16 |
Correct |
109 ms |
9168 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
204 KB |
Output is correct |
20 |
Correct |
113 ms |
9924 KB |
Output is correct |
21 |
Correct |
1 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
2 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
65 ms |
5924 KB |
Output is correct |
3 |
Correct |
69 ms |
5960 KB |
Output is correct |
4 |
Correct |
99 ms |
8624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
65 ms |
5924 KB |
Output is correct |
3 |
Correct |
69 ms |
5960 KB |
Output is correct |
4 |
Correct |
99 ms |
8624 KB |
Output is correct |
5 |
Correct |
113 ms |
9140 KB |
Output is correct |
6 |
Correct |
121 ms |
8672 KB |
Output is correct |
7 |
Correct |
101 ms |
8824 KB |
Output is correct |
8 |
Correct |
101 ms |
8628 KB |
Output is correct |
9 |
Correct |
67 ms |
5964 KB |
Output is correct |
10 |
Correct |
102 ms |
8612 KB |
Output is correct |
11 |
Correct |
105 ms |
8628 KB |
Output is correct |
12 |
Correct |
65 ms |
5928 KB |
Output is correct |
13 |
Correct |
68 ms |
6028 KB |
Output is correct |
14 |
Correct |
68 ms |
6052 KB |
Output is correct |
15 |
Correct |
75 ms |
6056 KB |
Output is correct |
16 |
Correct |
3 ms |
460 KB |
Output is correct |
17 |
Correct |
87 ms |
5800 KB |
Output is correct |
18 |
Correct |
63 ms |
5932 KB |
Output is correct |
19 |
Correct |
65 ms |
5980 KB |
Output is correct |
20 |
Correct |
98 ms |
8604 KB |
Output is correct |
21 |
Correct |
106 ms |
8624 KB |
Output is correct |
22 |
Correct |
103 ms |
8664 KB |
Output is correct |