#include "doll.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define mp make_pair
#define pub push_back
#define pob pop_back()
#define ss second
#define ff first
#define mt make_tuple
#define pof pop_front()
#define fbo find_by_order
#define ook order_of_key
#define lb lower_bound
#define ub upper_bound
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
using pll = pair <ll, ll>;
using pii = pair <int, int>;
int st[300001], n, k = 1, cnt, cur = 1;
vector<int> X, Y, C;
void solve(int res, int num, int at)
{
if ( num == 1 )
{
if ( res != 2 )
X[-at - 1] = -1;
} else {
if ( res <= num )
X[-at - 1] = -1;
else
X[-at - 1] = -(++cur);
Y[-at - 1] = -(++cur);
if ( res > num )
{
solve(res - num, num / 2, X[-at - 1]);
solve(num, num / 2, Y[-at - 1]);
} else{
solve(res, num / 2, Y[-at - 1]);
}
}
}
void dfs(int u, int j )
{
if ( !st[- u - 1] )
{
if ( X[- u - 1] == 0 )
{
X[- u - 1] = j;
st[- u - 1] = 1;
} else {
st[- u - 1] = 1;
dfs(X[- u - 1], j);
}
} else {
if ( Y[- u - 1] == 0 )
{
Y[- u - 1] = j;
st[- u - 1] = 0;
} else {
st[- u - 1] = 0;
dfs(Y[- u - 1], j);
}
}
}
void create_circuit(int M, vector<int> A) {
n = A.size();
C.pub(A[0]);
for (int i = 1; i <= M; i++)
C.pub(-1);
if ( n == 1 )
{
for (int i = 1; i <= M; i++)
C[i] = 0;
answer(C, X, Y);
return;
}
X.resize(n + log2(n));
Y.resize(n + log2(n));
while ( k < n )
k *= 2;
solve(n, k / 2, -1);
for (int i = 1; i < A.size(); i++)
dfs(-1, A[i]);
answer(C, X, Y);
}
Compilation message
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:102:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
102 | for (int i = 1; i < A.size(); i++)
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
48 ms |
4200 KB |
Output is correct |
3 |
Correct |
46 ms |
4056 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
15 ms |
1564 KB |
Output is correct |
6 |
Correct |
71 ms |
5072 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
48 ms |
4200 KB |
Output is correct |
3 |
Correct |
46 ms |
4056 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
15 ms |
1564 KB |
Output is correct |
6 |
Correct |
71 ms |
5072 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
99 ms |
6036 KB |
Output is correct |
9 |
Correct |
111 ms |
6288 KB |
Output is correct |
10 |
Correct |
134 ms |
8772 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
204 KB |
Output is correct |
2 |
Correct |
48 ms |
4200 KB |
Output is correct |
3 |
Correct |
46 ms |
4056 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
15 ms |
1564 KB |
Output is correct |
6 |
Correct |
71 ms |
5072 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
99 ms |
6036 KB |
Output is correct |
9 |
Correct |
111 ms |
6288 KB |
Output is correct |
10 |
Correct |
134 ms |
8772 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 |
129 ms |
8452 KB |
Output is correct |
15 |
Correct |
87 ms |
5540 KB |
Output is correct |
16 |
Correct |
143 ms |
8256 KB |
Output is correct |
17 |
Correct |
1 ms |
204 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
2 ms |
204 KB |
Output is correct |
20 |
Correct |
136 ms |
8652 KB |
Output is correct |
21 |
Correct |
2 ms |
204 KB |
Output is correct |
22 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
2 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 |
2 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
204 KB |
Output is correct |
7 |
Correct |
1 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
94 ms |
4912 KB |
Output is correct |
3 |
Correct |
88 ms |
4916 KB |
Output is correct |
4 |
Correct |
119 ms |
7276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
94 ms |
4912 KB |
Output is correct |
3 |
Correct |
88 ms |
4916 KB |
Output is correct |
4 |
Correct |
119 ms |
7276 KB |
Output is correct |
5 |
Correct |
126 ms |
8172 KB |
Output is correct |
6 |
Correct |
135 ms |
7816 KB |
Output is correct |
7 |
Correct |
129 ms |
7948 KB |
Output is correct |
8 |
Correct |
155 ms |
7708 KB |
Output is correct |
9 |
Correct |
84 ms |
4908 KB |
Output is correct |
10 |
Correct |
120 ms |
7556 KB |
Output is correct |
11 |
Correct |
118 ms |
7292 KB |
Output is correct |
12 |
Correct |
79 ms |
4940 KB |
Output is correct |
13 |
Correct |
79 ms |
5140 KB |
Output is correct |
14 |
Correct |
97 ms |
5304 KB |
Output is correct |
15 |
Correct |
83 ms |
5408 KB |
Output is correct |
16 |
Correct |
3 ms |
460 KB |
Output is correct |
17 |
Correct |
75 ms |
4928 KB |
Output is correct |
18 |
Correct |
76 ms |
4916 KB |
Output is correct |
19 |
Correct |
92 ms |
4932 KB |
Output is correct |
20 |
Correct |
124 ms |
7380 KB |
Output is correct |
21 |
Correct |
120 ms |
7364 KB |
Output is correct |
22 |
Correct |
131 ms |
7356 KB |
Output is correct |