#include "doll.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=2e5+7;
int lt[2*LIM], rt[2*LIM], ile[4*LIM], n, m, N=1;
int kier[2*LIM], nr[2*LIM], odw[2*LIM], akt, li;
int kl[2*LIM], kr[2*LIM];
vector<int>V;
void usun(int v, int k) {
if(v>=N) {
if(k==1) lt[v]=-1;
return;
}
if(k<=ile[2*v+1]) {
lt[v]=-1;
usun(2*v+1, k);
} else {
usun(2*v, k-ile[2*v+1]);
}
}
void create_circuit(int M, vector<int>A) {
V=A;
V.pb(0);
m=M;
n=V.size();
while(2*N<n) N*=2;
rep(i, 2*N) lt[i]=rt[i]=LIM;
rep(i, N) ile[N+i]=2;
for(int i=N-1; i; --i) {
lt[i]=-2*i;
rt[i]=-2*i-1;
ile[i]=ile[2*i]+ile[2*i+1];
}
usun(1, n);
int p=1;
while(li<n) {
if(!nr[p]) {
--akt;
nr[p]=akt;
}
kier[p]^=1;
if(kier[p]) {
if(lt[p]==LIM) {
lt[p]=V[li];
++li;
}
if(lt[p]>=0) p=1;
else p=-lt[p];
} else {
if(rt[p]==LIM) {
rt[p]=V[li];
++li;
}
if(rt[p]>=0) p=1;
else p=-rt[p];
}
}
p=1;
while(p) {
if(!odw[p]) {
if(lt[p]>=0) kl[-nr[p]]=lt[p];
else kl[-nr[p]]=nr[-lt[p]];
if(rt[p]>=0) kr[-nr[p]]=rt[p];
else kr[-nr[p]]=nr[-rt[p]];
odw[p]=1;
}
kier[p]^=1;
if(kier[p]) {
if(lt[p]>0) p=1;
else p=-lt[p];
} else {
if(rt[p]>0) p=1;
else p=-rt[p];
}
}
vector<int>C, X, Y;
rep(i, m+1) C.pb(-1);
for(int i=-1; i>=akt; --i) {
X.pb(kl[-i]);
Y.pb(kr[-i]);
}
answer(C, X, Y);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Correct |
47 ms |
7452 KB |
Output is correct |
3 |
Correct |
45 ms |
7240 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
9 ms |
1568 KB |
Output is correct |
6 |
Correct |
72 ms |
9692 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Correct |
47 ms |
7452 KB |
Output is correct |
3 |
Correct |
45 ms |
7240 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
9 ms |
1568 KB |
Output is correct |
6 |
Correct |
72 ms |
9692 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
92 ms |
12992 KB |
Output is correct |
9 |
Correct |
100 ms |
13328 KB |
Output is correct |
10 |
Correct |
134 ms |
17756 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
296 KB |
Output is correct |
13 |
Correct |
1 ms |
300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
300 KB |
Output is correct |
2 |
Correct |
47 ms |
7452 KB |
Output is correct |
3 |
Correct |
45 ms |
7240 KB |
Output is correct |
4 |
Correct |
1 ms |
296 KB |
Output is correct |
5 |
Correct |
9 ms |
1568 KB |
Output is correct |
6 |
Correct |
72 ms |
9692 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
92 ms |
12992 KB |
Output is correct |
9 |
Correct |
100 ms |
13328 KB |
Output is correct |
10 |
Correct |
134 ms |
17756 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
296 KB |
Output is correct |
13 |
Correct |
1 ms |
300 KB |
Output is correct |
14 |
Correct |
145 ms |
17484 KB |
Output is correct |
15 |
Correct |
96 ms |
13340 KB |
Output is correct |
16 |
Correct |
128 ms |
17972 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
0 ms |
332 KB |
Output is correct |
20 |
Correct |
139 ms |
17520 KB |
Output is correct |
21 |
Correct |
0 ms |
332 KB |
Output is correct |
22 |
Correct |
0 ms |
300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
300 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
85 ms |
10916 KB |
Output is correct |
3 |
Correct |
84 ms |
10852 KB |
Output is correct |
4 |
Correct |
156 ms |
14784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
85 ms |
10916 KB |
Output is correct |
3 |
Correct |
84 ms |
10852 KB |
Output is correct |
4 |
Correct |
156 ms |
14784 KB |
Output is correct |
5 |
Correct |
135 ms |
16680 KB |
Output is correct |
6 |
Correct |
129 ms |
15284 KB |
Output is correct |
7 |
Correct |
130 ms |
15360 KB |
Output is correct |
8 |
Correct |
141 ms |
16016 KB |
Output is correct |
9 |
Correct |
93 ms |
10920 KB |
Output is correct |
10 |
Correct |
136 ms |
14948 KB |
Output is correct |
11 |
Correct |
150 ms |
14704 KB |
Output is correct |
12 |
Correct |
85 ms |
10948 KB |
Output is correct |
13 |
Correct |
97 ms |
12188 KB |
Output is correct |
14 |
Correct |
85 ms |
11352 KB |
Output is correct |
15 |
Correct |
87 ms |
11516 KB |
Output is correct |
16 |
Correct |
2 ms |
676 KB |
Output is correct |
17 |
Correct |
78 ms |
10536 KB |
Output is correct |
18 |
Correct |
91 ms |
10888 KB |
Output is correct |
19 |
Correct |
88 ms |
10824 KB |
Output is correct |
20 |
Correct |
133 ms |
15928 KB |
Output is correct |
21 |
Correct |
130 ms |
14656 KB |
Output is correct |
22 |
Correct |
157 ms |
14612 KB |
Output is correct |