#include "doll.h"
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;
vector<int> X;
vector<int> Y;
vector<int> prec[50];
vector<int> constrv(int dep)
{
if(!prec[dep].empty())
return prec[dep];
vector<int> ans(1, 0);
for(int d = 0; d < dep; d++)
{
vector<int> nans;
for(int k = 0; k < (1 << d); k++)
{
nans.push_back(ans[k]);
nans.push_back(ans[k]+(1 << d));
}
ans = nans;
}
return prec[dep] = ans;
}
int constr(const vector<int>& rem, int l, int r)
{
bool eq = true;
for(int i = l; i <= r; i++) if(rem[i] != rem[l])
eq = false;
if(eq)
{
return rem[l];
}
int id = X.size();
X.push_back(0);
Y.push_back(0);
int na = constr(rem, l, l+(r-l+1)/2-1);
int nb = constr(rem, l+(r-l+1)/2, r);
X[id] = na;
Y[id] = nb;
return -id-1;
}
const int N = 2e5+5;
vector<int> pos[N];
void create_circuit(int M, std::vector<int> A) {
int N = A.size();
vector<int> st(M+1, -1);
pos[0].push_back(A[0]);
for(int i = 0; i < N-1; i++)
{
pos[0].push_back(A[i+1]);
}
pos[0].push_back(0);
for(int i = 0; i <= 0; i++)
{
if(pos[i].size() == 1)
{
st[i] = pos[i][0];
continue;
}
int ni = pos[i].size();
int log = __builtin_clz(1)-__builtin_clz((int)pos[i].size()-1)+1;
int p2 = (1 << log);
vector<int> m = constrv(log);
vector<pair<int, int>> pm;
for(int k = p2-ni; k < p2; k++)
{
pm.push_back({m[k], k});
}
vector<int> toc(p2, -X.size()-1);
sort(pm.begin(), pm.end());
for(int k = 0; k < pm.size(); k++)
{
auto [aa, bb] = pm[k];
toc[bb] = pos[i][k];
}
st[i] = constr(toc, 0, toc.size()-1);
}
answer(st, X, Y);
}
Compilation message
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:100:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
100 | for(int k = 0; k < pm.size(); k++)
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
30 ms |
10144 KB |
Output is correct |
3 |
Correct |
29 ms |
9956 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
12 ms |
6100 KB |
Output is correct |
6 |
Correct |
43 ms |
11708 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
30 ms |
10144 KB |
Output is correct |
3 |
Correct |
29 ms |
9956 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
12 ms |
6100 KB |
Output is correct |
6 |
Correct |
43 ms |
11708 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
49 ms |
13812 KB |
Output is correct |
9 |
Correct |
52 ms |
13868 KB |
Output is correct |
10 |
Correct |
90 ms |
16700 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
30 ms |
10144 KB |
Output is correct |
3 |
Correct |
29 ms |
9956 KB |
Output is correct |
4 |
Correct |
3 ms |
4948 KB |
Output is correct |
5 |
Correct |
12 ms |
6100 KB |
Output is correct |
6 |
Correct |
43 ms |
11708 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
49 ms |
13812 KB |
Output is correct |
9 |
Correct |
52 ms |
13868 KB |
Output is correct |
10 |
Correct |
90 ms |
16700 KB |
Output is correct |
11 |
Correct |
3 ms |
4948 KB |
Output is correct |
12 |
Correct |
2 ms |
4948 KB |
Output is correct |
13 |
Correct |
3 ms |
4948 KB |
Output is correct |
14 |
Correct |
78 ms |
16604 KB |
Output is correct |
15 |
Correct |
50 ms |
13716 KB |
Output is correct |
16 |
Correct |
76 ms |
16572 KB |
Output is correct |
17 |
Correct |
2 ms |
4948 KB |
Output is correct |
18 |
Correct |
2 ms |
4948 KB |
Output is correct |
19 |
Correct |
2 ms |
4948 KB |
Output is correct |
20 |
Correct |
89 ms |
16656 KB |
Output is correct |
21 |
Correct |
2 ms |
4948 KB |
Output is correct |
22 |
Correct |
2 ms |
4948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
4948 KB |
Output is correct |
2 |
Correct |
2 ms |
4948 KB |
Output is correct |
3 |
Correct |
2 ms |
4948 KB |
Output is correct |
4 |
Correct |
2 ms |
4948 KB |
Output is correct |
5 |
Correct |
2 ms |
4948 KB |
Output is correct |
6 |
Correct |
2 ms |
4948 KB |
Output is correct |
7 |
Correct |
2 ms |
4948 KB |
Output is correct |
8 |
Correct |
2 ms |
4992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
33 ms |
12100 KB |
Output is correct |
3 |
Correct |
25 ms |
12160 KB |
Output is correct |
4 |
Correct |
40 ms |
13452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4948 KB |
Output is correct |
2 |
Correct |
33 ms |
12100 KB |
Output is correct |
3 |
Correct |
25 ms |
12160 KB |
Output is correct |
4 |
Correct |
40 ms |
13452 KB |
Output is correct |
5 |
Correct |
75 ms |
16428 KB |
Output is correct |
6 |
Correct |
76 ms |
15332 KB |
Output is correct |
7 |
Correct |
73 ms |
16516 KB |
Output is correct |
8 |
Correct |
73 ms |
15108 KB |
Output is correct |
9 |
Correct |
40 ms |
12248 KB |
Output is correct |
10 |
Correct |
68 ms |
14736 KB |
Output is correct |
11 |
Correct |
70 ms |
14824 KB |
Output is correct |
12 |
Correct |
46 ms |
11964 KB |
Output is correct |
13 |
Correct |
58 ms |
13644 KB |
Output is correct |
14 |
Correct |
47 ms |
13292 KB |
Output is correct |
15 |
Correct |
48 ms |
13356 KB |
Output is correct |
16 |
Correct |
3 ms |
5204 KB |
Output is correct |
17 |
Correct |
43 ms |
11292 KB |
Output is correct |
18 |
Correct |
44 ms |
12420 KB |
Output is correct |
19 |
Correct |
47 ms |
12344 KB |
Output is correct |
20 |
Correct |
71 ms |
16184 KB |
Output is correct |
21 |
Correct |
71 ms |
16008 KB |
Output is correct |
22 |
Correct |
70 ms |
16080 KB |
Output is correct |