#include<bits/stdc++.h>
#include "doll.h"
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define N 500005
int l[N],r[N],sz,now;
bool sw[N];
bitset<N> ch,out;
vector<int> c,x,y,pos[N];
map<int,int> mp,id;
int bi(int x){
int i=1;
while(i<x)i<<=1;
return i;
}
int bic(int x){
int i=1,cnt=0;
while(i<x)i<<=1,cnt++;
return cnt;
}
int cre(int lev){
int s=++sz;
if(lev==1){
l[s]=-1;
r[s]=-1;
return s;
}
l[s]=(cre(lev-1));
r[s]=(cre(lev-1));
return s;
}
void dfs(int s,int st,int head,vector<int> &a){
if(now<=0)return ;
if(!sw[s]){
sw[s]^=1;
if(l[s]==-1){
ch[s]=true;
int ps=pos[head].size();
if(now<=ps)l[s]=-a[pos[head][ps-now]+1];
else l[s]=st;
now--;
dfs(st,st,head,a);
}
else dfs(l[s],st,head,a);
}
else{
sw[s]^=1;
if(r[s]==-1){
int ps=pos[head].size();
if(now<=ps)r[s]=-a[pos[head][ps-now]+1];
else r[s]=st;
now--;
dfs(st,st,head,a);
}
else dfs(r[s],st,head,a);
}
}
void upd(int s,int st,int f,vector<int> &a){
if(ch[s]){
if(l[s]==st&&r[s]==st)l[s]=r[s]=f;
return ;
}
upd(l[s],st,s,a);
upd(r[s],st,s,a);
if(l[l[s]]==f&&r[l[s]]==f&&l[r[s]]==f&&r[r[s]]==f){
out[l[s]]=true;
l[s]=f;
out[r[s]]=true;
r[s]=f;
}
}
void create_circuit(int m,vector<int> a){
int i;
c.resize(m+1);
c[0]=a[0];
i=0;
for(auto x:a){
mp[x]++;
pos[x].push_back(i);
i++;
}
a.push_back(0);
for(auto [x,y]:mp){
if(mp[x]==1)c[x]=a[pos[x][0]+1];
else{
now=bi(y);
c[x]=-cre(bic(y));
dfs(-c[x],-c[x],x,a);
upd(-c[x],-c[x],x,a);
}
}
now=0;
for(i=1;i<=sz;i++)if(!out[i])id[i]=--now;
for(auto &x:c)if(x<0)x=id[-x];
for(i=1;i<=sz;i++){
if(l[i]>0)x.push_back(id[l[i]]);
else x.push_back(-l[i]);
if(r[i]>0)y.push_back(id[r[i]]);
else y.push_back(-r[i]);
}
answer(c,x,y);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11988 KB |
Output is correct |
2 |
Correct |
67 ms |
18980 KB |
Output is correct |
3 |
Correct |
64 ms |
18640 KB |
Output is correct |
4 |
Correct |
6 ms |
11988 KB |
Output is correct |
5 |
Correct |
15 ms |
13140 KB |
Output is correct |
6 |
Correct |
99 ms |
22076 KB |
Output is correct |
7 |
Correct |
7 ms |
11988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11988 KB |
Output is correct |
2 |
Correct |
67 ms |
18980 KB |
Output is correct |
3 |
Correct |
64 ms |
18640 KB |
Output is correct |
4 |
Correct |
6 ms |
11988 KB |
Output is correct |
5 |
Correct |
15 ms |
13140 KB |
Output is correct |
6 |
Correct |
99 ms |
22076 KB |
Output is correct |
7 |
Correct |
7 ms |
11988 KB |
Output is correct |
8 |
Correct |
137 ms |
25084 KB |
Output is correct |
9 |
Correct |
132 ms |
25288 KB |
Output is correct |
10 |
Correct |
204 ms |
32236 KB |
Output is correct |
11 |
Correct |
7 ms |
11988 KB |
Output is correct |
12 |
Correct |
9 ms |
12052 KB |
Output is correct |
13 |
Correct |
8 ms |
12056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11988 KB |
Output is correct |
2 |
Correct |
67 ms |
18980 KB |
Output is correct |
3 |
Correct |
64 ms |
18640 KB |
Output is correct |
4 |
Correct |
6 ms |
11988 KB |
Output is correct |
5 |
Correct |
15 ms |
13140 KB |
Output is correct |
6 |
Correct |
99 ms |
22076 KB |
Output is correct |
7 |
Correct |
7 ms |
11988 KB |
Output is correct |
8 |
Correct |
137 ms |
25084 KB |
Output is correct |
9 |
Correct |
132 ms |
25288 KB |
Output is correct |
10 |
Correct |
204 ms |
32236 KB |
Output is correct |
11 |
Correct |
7 ms |
11988 KB |
Output is correct |
12 |
Correct |
9 ms |
12052 KB |
Output is correct |
13 |
Correct |
8 ms |
12056 KB |
Output is correct |
14 |
Correct |
239 ms |
38064 KB |
Output is correct |
15 |
Correct |
113 ms |
25016 KB |
Output is correct |
16 |
Correct |
189 ms |
31628 KB |
Output is correct |
17 |
Correct |
6 ms |
11988 KB |
Output is correct |
18 |
Correct |
6 ms |
12052 KB |
Output is correct |
19 |
Correct |
6 ms |
12052 KB |
Output is correct |
20 |
Correct |
229 ms |
34552 KB |
Output is correct |
21 |
Correct |
8 ms |
11988 KB |
Output is correct |
22 |
Correct |
6 ms |
11988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
11988 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
6 ms |
11988 KB |
Output is partially correct |
2 |
Correct |
106 ms |
25960 KB |
Output is correct |
3 |
Partially correct |
208 ms |
35524 KB |
Output is partially correct |
4 |
Partially correct |
267 ms |
37832 KB |
Output is partially correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
6 ms |
11988 KB |
Output is partially correct |
2 |
Correct |
106 ms |
25960 KB |
Output is correct |
3 |
Partially correct |
208 ms |
35524 KB |
Output is partially correct |
4 |
Partially correct |
267 ms |
37832 KB |
Output is partially correct |
5 |
Partially correct |
304 ms |
44724 KB |
Output is partially correct |
6 |
Partially correct |
289 ms |
47908 KB |
Output is partially correct |
7 |
Partially correct |
273 ms |
46736 KB |
Output is partially correct |
8 |
Partially correct |
273 ms |
49596 KB |
Output is partially correct |
9 |
Partially correct |
199 ms |
35812 KB |
Output is partially correct |
10 |
Partially correct |
301 ms |
49716 KB |
Output is partially correct |
11 |
Partially correct |
297 ms |
51024 KB |
Output is partially correct |
12 |
Partially correct |
197 ms |
36756 KB |
Output is partially correct |
13 |
Partially correct |
197 ms |
34512 KB |
Output is partially correct |
14 |
Partially correct |
190 ms |
33788 KB |
Output is partially correct |
15 |
Partially correct |
188 ms |
32564 KB |
Output is partially correct |
16 |
Partially correct |
10 ms |
12628 KB |
Output is partially correct |
17 |
Partially correct |
149 ms |
31324 KB |
Output is partially correct |
18 |
Partially correct |
167 ms |
31344 KB |
Output is partially correct |
19 |
Partially correct |
146 ms |
32808 KB |
Output is partially correct |
20 |
Partially correct |
192 ms |
39728 KB |
Output is partially correct |
21 |
Partially correct |
223 ms |
45872 KB |
Output is partially correct |
22 |
Partially correct |
184 ms |
38112 KB |
Output is partially correct |