#include <bits/stdc++.h>
#ifndef SKY
#include "doll.h"
#endif // SKY
using namespace std;
#define N 1000010
#define ll long long
#define fs first
#define sc second
#define ii pair<int,int>
#define pb push_back
int n,q,dem=0,root[N];
vector<int>lis[N];
vector<ii>flow_out[N];
vector<int>a,C,X,Y;
#ifdef SKY
void answer(vector<int>C,vector<int>X,vector<int>Y)
{
for(auto u:C)cout<<u<<" ";cout<<endl;
for(int i=0;i<X.size();i++)cout<<X[i]<<" "<<Y[i]<<endl;
}
#endif // SKY
void my_answer(vector<int>C,vector<int>X,vector<int>Y)
{
assert(X.size()<=q+log2(q));
answer(C,X,Y);
}
struct haha
{
int child[2]={},tt=0;
}node[N];
void build(int u,int h)
{
if(h==0)
return;
node[u].child[0]=++dem;
node[u].child[1]=++dem;
build(node[u].child[0],h-1);
build(node[u].child[1],h-1);
}
ii DFS(int u)
{
if(node[u].child[0]==0)
{
ii res={u,node[u].tt};
node[u].tt^=1;
return res;
}
node[u].tt^=1;
return DFS(node[u].child[(node[u].tt^1)]);
}
void solve(int u)
{
int k=ceil(log2(lis[u].size()));
dem++;
C[u]=-dem;
int moc=dem;
root[u]=moc;
build(moc,k-1);
while(1)
{
ii cc=DFS(moc);
if(!flow_out[u].empty()&&cc==flow_out[u][0])
break;
//cout<<"cc\n";
flow_out[u].pb(cc);
}
for(auto cc:flow_out[u])
node[cc.fs].child[cc.sc]=moc;
int pos=dem;
while(!lis[u].empty())
{
ii cc=flow_out[u].back();
flow_out[u].pop_back();
int i=lis[u].back();
lis[u].pop_back();
if(i==q-1)
{
node[cc.fs].child[cc.sc]=0;
}else
{
node[cc.fs].child[cc.sc]=-a[i+1];
}
}
}
void create_circuit(int cc, vector<int> vec)
{
a=vec;
n=cc;
q=a.size();
// cout<<m<<" "<<n<<endl;
for(int i=0;i<q;i++)
lis[a[i]].pb(i);
// for(int i=1;i<=n;i++)cout<<lis[i].size()<<endl;
C.resize(n+1,0);
C[0]=a[0];
for(int i=1;i<=n;i++)
if(!lis[i].empty())
{
if(lis[i].size()==1)
{
if(lis[i].back()!=q-1)
C[i]=a[lis[i].back()+1];
continue;
}
solve(i);
}
for(int i=1;i<=dem;i++)
X.pb(-node[i].child[0]),Y.pb(-node[i].child[1]);
my_answer(C,X,Y);
}
#ifdef SKY
int main()
{
freopen("A.inp","r",stdin);
freopen("A.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
int m,n;
cin>>m>>n;
vector<int>a;
for(int i=1;i<=n;i++)
{
int u;
cin>>u;
a.pb(u);
}
create_circuit(m,a);
return 0;
}
#endif
Compilation message
doll.cpp: In function 'void solve(int)':
doll.cpp:80:9: warning: unused variable 'pos' [-Wunused-variable]
80 | int pos=dem;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
47188 KB |
Output is correct |
2 |
Correct |
50 ms |
51588 KB |
Output is correct |
3 |
Correct |
50 ms |
51132 KB |
Output is correct |
4 |
Correct |
27 ms |
47268 KB |
Output is correct |
5 |
Correct |
32 ms |
48852 KB |
Output is correct |
6 |
Correct |
67 ms |
53068 KB |
Output is correct |
7 |
Correct |
22 ms |
47188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
47188 KB |
Output is correct |
2 |
Correct |
50 ms |
51588 KB |
Output is correct |
3 |
Correct |
50 ms |
51132 KB |
Output is correct |
4 |
Correct |
27 ms |
47268 KB |
Output is correct |
5 |
Correct |
32 ms |
48852 KB |
Output is correct |
6 |
Correct |
67 ms |
53068 KB |
Output is correct |
7 |
Correct |
22 ms |
47188 KB |
Output is correct |
8 |
Correct |
76 ms |
57184 KB |
Output is correct |
9 |
Correct |
79 ms |
56824 KB |
Output is correct |
10 |
Correct |
129 ms |
62356 KB |
Output is correct |
11 |
Correct |
28 ms |
47144 KB |
Output is correct |
12 |
Correct |
26 ms |
47188 KB |
Output is correct |
13 |
Correct |
24 ms |
47276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
24 ms |
47188 KB |
Output is correct |
2 |
Correct |
50 ms |
51588 KB |
Output is correct |
3 |
Correct |
50 ms |
51132 KB |
Output is correct |
4 |
Correct |
27 ms |
47268 KB |
Output is correct |
5 |
Correct |
32 ms |
48852 KB |
Output is correct |
6 |
Correct |
67 ms |
53068 KB |
Output is correct |
7 |
Correct |
22 ms |
47188 KB |
Output is correct |
8 |
Correct |
76 ms |
57184 KB |
Output is correct |
9 |
Correct |
79 ms |
56824 KB |
Output is correct |
10 |
Correct |
129 ms |
62356 KB |
Output is correct |
11 |
Correct |
28 ms |
47144 KB |
Output is correct |
12 |
Correct |
26 ms |
47188 KB |
Output is correct |
13 |
Correct |
24 ms |
47276 KB |
Output is correct |
14 |
Correct |
132 ms |
64788 KB |
Output is correct |
15 |
Correct |
96 ms |
56256 KB |
Output is correct |
16 |
Correct |
123 ms |
60984 KB |
Output is correct |
17 |
Correct |
24 ms |
47224 KB |
Output is correct |
18 |
Correct |
22 ms |
47208 KB |
Output is correct |
19 |
Correct |
22 ms |
47188 KB |
Output is correct |
20 |
Correct |
104 ms |
62860 KB |
Output is correct |
21 |
Correct |
23 ms |
47252 KB |
Output is correct |
22 |
Correct |
22 ms |
47180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
67 ms |
95756 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
63 ms |
95660 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
63 ms |
95660 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |