#include <bits/stdc++.h>
#include "doll.h"
#warning That's not FB, that's my FB
using namespace std;
int n,m;
vector<int> a;
vector<vector<int>> pos;
vector<int> unde;
int cur = 1;
vector<int> c, x, y;
int ngl, kgl, pgl;
void build(int nume, int l, int r)
{
int mij = (l + r) / 2;
if (mij <= pgl)
x[-nume - 1] = c[ngl];
else
{
if (l != mij)
{
x[-nume - 1] = -cur;
cur++;
x.push_back(0);
y.push_back(0);
build(x[-nume - 1], l, mij);
}
else
{
//int pz = pos[ngl][unde[ngl]] + 1;
//unde[ngl]++;
x[-nume - 1] = 3 * n;
}
}
if (mij + 1 != r)
{
y[-nume - 1] = -cur;
cur++;
x.push_back(0);
y.push_back(0);
build(y[-nume - 1], mij + 1, r);
}
else
{
//int pz = pos[ngl][unde[ngl]] + 1;
//unde[ngl]++;
y[-nume - 1] = 3 * n;
}
}
void build_sgt(int nod)
{
c[nod] = -cur;
cur++;
x.push_back(0);
y.push_back(0);
ngl = nod;
kgl = __lg(pos[nod].size());
if ((1 << kgl) < pos[nod].size())
kgl++;
pgl = (1 << kgl) - (int)pos[nod].size();
build(c[nod], 1, (1 << kgl));
}
int cr = 0;
vector<int> how;
void gogo(int nod)
{
//cout << nod << endl;
if (nod == 0)
return;
if (nod >= 1)
{
cr++;
gogo(c[nod]);
return;
}
//cout << x[-nod - 1] << ' ' << y[-nod - 1] << ' ' << how[-nod - 1] << endl;
if (how[-nod - 1] == 0)
{
how[-nod - 1] = 1;
if (x[-nod - 1] > 2 * n)
{
x[-nod - 1] = a[cr];
//cr++;
}
gogo(x[-nod - 1]);
}
else
{
how[-nod - 1] = 0;
if (y[-nod - 1] > 2 * n)
{
y[-nod - 1] = a[cr];
//cr++;
}
gogo(y[-nod - 1]);
}
}
void create_circuit(int M, vector<int> A)
{
n = A.size();
a = A;
m = M;
pos.resize(m + 1);
unde.resize(m + 1);
for (int i = 0; i < a.size(); i++)
pos[a[i]].push_back(i);
a.push_back(0);
c.resize(m + 1);
c[0] = a[0];
for (int i = 1; i <= m; i++)
{
if (pos[i].empty())
c[i] = 0;
else if (pos[i].size() == 1)
c[i] = a[pos[i][0] + 1];
else
build_sgt(i);
}
/*for (auto it : c)
cout << it << ' ';
cout << endl;
for (auto it : x)
cout << it << ' ';
cout << endl;
for (auto it : y)
cout << it << ' ';
cout << endl;*/
how.resize(cur);
gogo(a[0]);
answer(c, x, y);
}
Compilation message
doll.cpp:3:2: warning: #warning That's not FB, that's my FB [-Wcpp]
3 | #warning That's not FB, that's my FB
| ^~~~~~~
doll.cpp: In function 'void build_sgt(int)':
doll.cpp:63:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | if ((1 << kgl) < pos[nod].size())
| ~~~~~~~~~~~^~~~~~~~~~~~~~~~~
doll.cpp: In function 'void create_circuit(int, std::vector<int>)':
doll.cpp:113:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
113 | for (int i = 0; i < a.size(); i++)
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
16 ms |
7180 KB |
Output is correct |
3 |
Correct |
14 ms |
5972 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
7 ms |
4184 KB |
Output is correct |
6 |
Correct |
20 ms |
8780 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
16 ms |
7180 KB |
Output is correct |
3 |
Correct |
14 ms |
5972 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
7 ms |
4184 KB |
Output is correct |
6 |
Correct |
20 ms |
8780 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
29 ms |
8988 KB |
Output is correct |
9 |
Correct |
34 ms |
10236 KB |
Output is correct |
10 |
Correct |
46 ms |
14072 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
16 ms |
7180 KB |
Output is correct |
3 |
Correct |
14 ms |
5972 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
7 ms |
4184 KB |
Output is correct |
6 |
Correct |
20 ms |
8780 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
29 ms |
8988 KB |
Output is correct |
9 |
Correct |
34 ms |
10236 KB |
Output is correct |
10 |
Correct |
46 ms |
14072 KB |
Output is correct |
11 |
Correct |
1 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
53 ms |
15176 KB |
Output is correct |
15 |
Correct |
30 ms |
9036 KB |
Output is correct |
16 |
Correct |
48 ms |
13108 KB |
Output is correct |
17 |
Correct |
0 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
53 ms |
15572 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
47 ms |
7104 KB |
Output is correct |
3 |
Correct |
48 ms |
6644 KB |
Output is correct |
4 |
Correct |
71 ms |
10148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
47 ms |
7104 KB |
Output is correct |
3 |
Correct |
48 ms |
6644 KB |
Output is correct |
4 |
Correct |
71 ms |
10148 KB |
Output is correct |
5 |
Partially correct |
61 ms |
14044 KB |
Output is partially correct |
6 |
Partially correct |
66 ms |
13244 KB |
Output is partially correct |
7 |
Partially correct |
61 ms |
13504 KB |
Output is partially correct |
8 |
Partially correct |
55 ms |
12404 KB |
Output is partially correct |
9 |
Partially correct |
55 ms |
6704 KB |
Output is partially correct |
10 |
Partially correct |
68 ms |
11020 KB |
Output is partially correct |
11 |
Partially correct |
69 ms |
10304 KB |
Output is partially correct |
12 |
Partially correct |
43 ms |
7620 KB |
Output is partially correct |
13 |
Partially correct |
42 ms |
8500 KB |
Output is partially correct |
14 |
Partially correct |
41 ms |
8852 KB |
Output is partially correct |
15 |
Partially correct |
40 ms |
9120 KB |
Output is partially correct |
16 |
Partially correct |
2 ms |
600 KB |
Output is partially correct |
17 |
Partially correct |
44 ms |
6676 KB |
Output is partially correct |
18 |
Partially correct |
39 ms |
7288 KB |
Output is partially correct |
19 |
Partially correct |
44 ms |
6528 KB |
Output is partially correct |
20 |
Partially correct |
57 ms |
10472 KB |
Output is partially correct |
21 |
Partially correct |
65 ms |
10052 KB |
Output is partially correct |
22 |
Partially correct |
58 ms |
10052 KB |
Output is partially correct |