#include "doll.h"
#include<bits/stdc++.h>
#define pii pair<int,int>
#define x first
#define y second
using namespace std;
vector<int>to[200015],g[200015];
vector<int>ans1,ans2,c;
int n,m,now=0,vis[400015];
pii seg[400015];
int build(int num,int l,int r,int root,int out){
if (l==r){
if (out) return root;
return -root;
}
int mid=(l+r)>>1,use=--now;
use=abs(use);
if (out<(mid-l+1)){
seg[use].x=build(num,l,mid,root,out);
seg[use].y=build(num,mid+1,r,root,0);
}
else {
out-=(mid-l+1);
seg[use].x=root;
seg[use].y=build(num,mid+1,r,root,out);
}
return use;
}
void dfs(int num,int i,int order,int root){
if (order==g[num].size()) return;
if (!vis[i]){
vis[i]^=1;
if (seg[i].x==-root)
ans1[i]=g[num][order++];
else ans1[i]=-seg[i].x;
dfs(num,abs(seg[i].x),order,root);
}
else {
vis[i]^=1;
if (seg[i].y==-root)
ans2[i]=g[num][order++];
else ans2[i]=-seg[i].y;
dfs(num,abs(seg[i].y),order,root);
}
return;
}
void create_circuit(int M, std::vector<int> A) {
m=M;
ans1.resize(400000); ans2.resize(400000);
A.push_back(0);
n = A.size();
for (int i=0;i<n-1;i++){
g[A[i]].push_back(A[i+1]);
}
c.resize(m+1);
int now_root=0;
for (int i=0;i<=m;i++){
if (g[i].empty()) c[i]=0;
else if (g[i].size()==1) c[i]=g[i][0];
else {
int p=__lg((int)(g[i].size()-1))+1;
now_root=abs(now)+1;
c[i]=-now_root;
build(i,0,(1LL<<p)-1,now_root,(1LL<<p)-g[i].size());
dfs(i,now_root,0,now_root);
}
}
c[0]=A[0];
now=abs(now);
vector<int>X,Y;
for (int i=1;i<=now;i++){
X.push_back(ans1[i]);
}
for (int i=1;i<=now;i++){
Y.push_back(ans2[i]);
}
answer(c, X, Y);
}
/*
2 16
1 2 2 1 2 2 1 1 1 1 2 2 2 1 2 2 2 1 1 2 2 2 1
4 5
1 2 1 3 1
./rand
./doll
*/
Compilation message
doll.cpp: In function 'void dfs(int, int, int, int)':
doll.cpp:30:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
30 | if (order==g[num].size()) return;
| ~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12772 KB |
Output is correct |
2 |
Correct |
38 ms |
16656 KB |
Output is correct |
3 |
Correct |
26 ms |
16324 KB |
Output is correct |
4 |
Correct |
7 ms |
12756 KB |
Output is correct |
5 |
Correct |
14 ms |
13908 KB |
Output is correct |
6 |
Correct |
37 ms |
18160 KB |
Output is correct |
7 |
Correct |
7 ms |
12756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12772 KB |
Output is correct |
2 |
Correct |
38 ms |
16656 KB |
Output is correct |
3 |
Correct |
26 ms |
16324 KB |
Output is correct |
4 |
Correct |
7 ms |
12756 KB |
Output is correct |
5 |
Correct |
14 ms |
13908 KB |
Output is correct |
6 |
Correct |
37 ms |
18160 KB |
Output is correct |
7 |
Correct |
7 ms |
12756 KB |
Output is correct |
8 |
Correct |
51 ms |
19960 KB |
Output is correct |
9 |
Correct |
51 ms |
20036 KB |
Output is correct |
10 |
Correct |
84 ms |
23464 KB |
Output is correct |
11 |
Correct |
7 ms |
12768 KB |
Output is correct |
12 |
Correct |
7 ms |
12756 KB |
Output is correct |
13 |
Correct |
7 ms |
12756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12772 KB |
Output is correct |
2 |
Correct |
38 ms |
16656 KB |
Output is correct |
3 |
Correct |
26 ms |
16324 KB |
Output is correct |
4 |
Correct |
7 ms |
12756 KB |
Output is correct |
5 |
Correct |
14 ms |
13908 KB |
Output is correct |
6 |
Correct |
37 ms |
18160 KB |
Output is correct |
7 |
Correct |
7 ms |
12756 KB |
Output is correct |
8 |
Correct |
51 ms |
19960 KB |
Output is correct |
9 |
Correct |
51 ms |
20036 KB |
Output is correct |
10 |
Correct |
84 ms |
23464 KB |
Output is correct |
11 |
Correct |
7 ms |
12768 KB |
Output is correct |
12 |
Correct |
7 ms |
12756 KB |
Output is correct |
13 |
Correct |
7 ms |
12756 KB |
Output is correct |
14 |
Correct |
90 ms |
25168 KB |
Output is correct |
15 |
Correct |
49 ms |
19780 KB |
Output is correct |
16 |
Correct |
75 ms |
22100 KB |
Output is correct |
17 |
Correct |
7 ms |
12756 KB |
Output is correct |
18 |
Correct |
7 ms |
12756 KB |
Output is correct |
19 |
Correct |
7 ms |
12756 KB |
Output is correct |
20 |
Correct |
79 ms |
23656 KB |
Output is correct |
21 |
Correct |
7 ms |
12756 KB |
Output is correct |
22 |
Correct |
7 ms |
12884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
12756 KB |
Output is correct |
2 |
Correct |
7 ms |
12772 KB |
Output is correct |
3 |
Correct |
7 ms |
12772 KB |
Output is correct |
4 |
Correct |
7 ms |
12756 KB |
Output is correct |
5 |
Correct |
7 ms |
12768 KB |
Output is correct |
6 |
Correct |
8 ms |
12744 KB |
Output is correct |
7 |
Correct |
7 ms |
12756 KB |
Output is correct |
8 |
Correct |
7 ms |
12756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12756 KB |
Output is correct |
2 |
Correct |
71 ms |
20520 KB |
Output is correct |
3 |
Correct |
68 ms |
19084 KB |
Output is correct |
4 |
Correct |
117 ms |
22304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12756 KB |
Output is correct |
2 |
Correct |
71 ms |
20520 KB |
Output is correct |
3 |
Correct |
68 ms |
19084 KB |
Output is correct |
4 |
Correct |
117 ms |
22304 KB |
Output is correct |
5 |
Partially correct |
95 ms |
25524 KB |
Output is partially correct |
6 |
Partially correct |
95 ms |
25356 KB |
Output is partially correct |
7 |
Partially correct |
93 ms |
25404 KB |
Output is partially correct |
8 |
Partially correct |
95 ms |
24804 KB |
Output is partially correct |
9 |
Partially correct |
66 ms |
19156 KB |
Output is partially correct |
10 |
Partially correct |
98 ms |
23812 KB |
Output is partially correct |
11 |
Partially correct |
79 ms |
23660 KB |
Output is partially correct |
12 |
Partially correct |
54 ms |
20000 KB |
Output is partially correct |
13 |
Partially correct |
66 ms |
21088 KB |
Output is partially correct |
14 |
Partially correct |
67 ms |
21232 KB |
Output is partially correct |
15 |
Partially correct |
65 ms |
21192 KB |
Output is partially correct |
16 |
Partially correct |
8 ms |
13140 KB |
Output is partially correct |
17 |
Partially correct |
54 ms |
19656 KB |
Output is partially correct |
18 |
Partially correct |
56 ms |
19460 KB |
Output is partially correct |
19 |
Partially correct |
52 ms |
19664 KB |
Output is partially correct |
20 |
Partially correct |
77 ms |
23276 KB |
Output is partially correct |
21 |
Partially correct |
80 ms |
23296 KB |
Output is partially correct |
22 |
Partially correct |
77 ms |
22896 KB |
Output is partially correct |