#include "doll.h"
#include <bits/stdc++.h>
using namespace std;
const int MX = (int)(1e5+5);
#define sz(x) (int)(x.size())
int log_2(int x){
return 31-__builtin_clz(x);
}
vector<int> occ[MX],C;
bool state[4*MX],last[4*MX];
int idx=1,X[4*MX],Y[4*MX],a[2*MX];
// fix indexes 2*i is wrong, must assign indexes dynamically
void gimme(int x){
//sz(oc[x])==1
int nb=(1<<(log_2(sz(occ[x])-1)+1))-1;
int sum=0,st=idx+1,comp=0;
vector<int> vec={idx};
while((sum+sz(vec))< nb){
vector<int> G;
for(auto it:vec){
X[it]=-st;
G.push_back(st),st++;
Y[it]=-st;
G.push_back(st),st++;
}
sum+=sz(vec);
vec=G;
}
C[x]=-idx;
for (int i = idx; i <= idx+nb-1; ++i)
last[idx]=0;
for(auto it:vec)
last[it]=1;
for (int i = 0; i < nb+1; ++i)
{
int r=-idx;
while(!last[-r]){
state[-r]=(!state[-r]);
if(state[-r])r=X[-r];
else r=Y[-r];
}
if((nb-i)<sz(occ[x])){
/*cerr<<-r<<" ";
cerr<<a[occ[x][comp]+1]<<"\n";*/
//cerr<<nb-i<<"\n";
if(!state[-r])X[-r]=a[occ[x][comp]+1];
else Y[-r]=a[occ[x][comp]+1];
comp++;
}
else {
if(!state[-r])X[-r]=-idx;
else Y[-r]=-idx;
}
state[-r]=(!state[-r]);
}
/*for (int i = idx; i <= idx+nb-1; ++i)
cerr<<i<<" : "<<X[i]<<" "<<Y[i]<<"\n";
*/
idx+=nb;
}
void create_circuit(int M, vector<int> A) {
for (int i = 0; i < sz(A); ++i)
occ[A[i]].push_back(i),a[i]=A[i];
a[sz(A)]=0;
A.push_back(0);
C.resize(M+1);
C[0]=A[0];
for (int i = 0; i < sz(A)-1; ++i)
if(occ[A[i]][0]==i)
gimme(A[i]);
vector<int> x(idx-1),y(idx-1);
for (int i = 1; i < idx; ++i){
x[i-1]=X[i],y[i-1]=Y[i];
}
answer(C, x, y);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2608 KB |
Output is correct |
2 |
Correct |
66 ms |
9912 KB |
Output is correct |
3 |
Correct |
48 ms |
9804 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
17 ms |
3788 KB |
Output is correct |
6 |
Correct |
78 ms |
13652 KB |
Output is correct |
7 |
Correct |
3 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2608 KB |
Output is correct |
2 |
Correct |
66 ms |
9912 KB |
Output is correct |
3 |
Correct |
48 ms |
9804 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
17 ms |
3788 KB |
Output is correct |
6 |
Correct |
78 ms |
13652 KB |
Output is correct |
7 |
Correct |
3 ms |
2636 KB |
Output is correct |
8 |
Correct |
86 ms |
10456 KB |
Output is correct |
9 |
Correct |
95 ms |
12976 KB |
Output is correct |
10 |
Correct |
129 ms |
14440 KB |
Output is correct |
11 |
Correct |
2 ms |
2636 KB |
Output is correct |
12 |
Correct |
3 ms |
2636 KB |
Output is correct |
13 |
Correct |
3 ms |
2636 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2608 KB |
Output is correct |
2 |
Correct |
66 ms |
9912 KB |
Output is correct |
3 |
Correct |
48 ms |
9804 KB |
Output is correct |
4 |
Correct |
2 ms |
2636 KB |
Output is correct |
5 |
Correct |
17 ms |
3788 KB |
Output is correct |
6 |
Correct |
78 ms |
13652 KB |
Output is correct |
7 |
Correct |
3 ms |
2636 KB |
Output is correct |
8 |
Correct |
86 ms |
10456 KB |
Output is correct |
9 |
Correct |
95 ms |
12976 KB |
Output is correct |
10 |
Correct |
129 ms |
14440 KB |
Output is correct |
11 |
Correct |
2 ms |
2636 KB |
Output is correct |
12 |
Correct |
3 ms |
2636 KB |
Output is correct |
13 |
Correct |
3 ms |
2636 KB |
Output is correct |
14 |
Correct |
127 ms |
17584 KB |
Output is correct |
15 |
Correct |
62 ms |
10672 KB |
Output is correct |
16 |
Correct |
102 ms |
14620 KB |
Output is correct |
17 |
Correct |
3 ms |
2692 KB |
Output is correct |
18 |
Correct |
4 ms |
2636 KB |
Output is correct |
19 |
Correct |
2 ms |
2636 KB |
Output is correct |
20 |
Correct |
120 ms |
16644 KB |
Output is correct |
21 |
Correct |
3 ms |
2636 KB |
Output is correct |
22 |
Correct |
3 ms |
2640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
4 ms |
2636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
3 ms |
2644 KB |
Output is partially correct |
2 |
Correct |
71 ms |
10404 KB |
Output is correct |
3 |
Partially correct |
131 ms |
13956 KB |
Output is partially correct |
4 |
Partially correct |
147 ms |
15272 KB |
Output is partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
3 ms |
2644 KB |
Output is partially correct |
2 |
Correct |
71 ms |
10404 KB |
Output is correct |
3 |
Partially correct |
131 ms |
13956 KB |
Output is partially correct |
4 |
Partially correct |
147 ms |
15272 KB |
Output is partially correct |
5 |
Partially correct |
146 ms |
17580 KB |
Output is partially correct |
6 |
Partially correct |
159 ms |
18868 KB |
Output is partially correct |
7 |
Partially correct |
204 ms |
18440 KB |
Output is partially correct |
8 |
Partially correct |
141 ms |
19716 KB |
Output is partially correct |
9 |
Partially correct |
116 ms |
13836 KB |
Output is partially correct |
10 |
Partially correct |
176 ms |
20084 KB |
Output is partially correct |
11 |
Partially correct |
136 ms |
20444 KB |
Output is partially correct |
12 |
Partially correct |
88 ms |
14272 KB |
Output is partially correct |
13 |
Partially correct |
88 ms |
13336 KB |
Output is partially correct |
14 |
Partially correct |
106 ms |
12940 KB |
Output is partially correct |
15 |
Partially correct |
94 ms |
12488 KB |
Output is partially correct |
16 |
Partially correct |
5 ms |
3020 KB |
Output is partially correct |
17 |
Partially correct |
75 ms |
11920 KB |
Output is partially correct |
18 |
Partially correct |
81 ms |
11804 KB |
Output is partially correct |
19 |
Partially correct |
76 ms |
12376 KB |
Output is partially correct |
20 |
Partially correct |
105 ms |
15256 KB |
Output is partially correct |
21 |
Partially correct |
130 ms |
17884 KB |
Output is partially correct |
22 |
Partially correct |
102 ms |
14556 KB |
Output is partially correct |