-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
55 lines (53 loc) · 1.13 KB
/
Copy pathmain.cpp
File metadata and controls
55 lines (53 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <bits/stdc++.h>
using namespace std;
auto sol = [](int n, auto v) {
vector ret(0, 0);
deque dq(0, 0);
for (int i = 2; i <= n; i++) dq.push_back(i);
int x = 1;
if (x == v[2]) {
ret.push_back(1);
swap(x, dq.front());
}
for (int i = 3; i <= n; i++) {
if (x != v[i]) {
while (dq.front() != v[i]) {
ret.push_back(2);
dq.push_back(dq.front());
dq.pop_front();
}
ret.push_back(1);
swap(x, dq.front());
}
while (dq.back() != v[i - 1]) {
ret.push_back(2);
dq.push_back(dq.front());
dq.pop_front();
}
ret.push_back(1);
swap(x, dq.front());
}
while (dq.front() != v[2]) {
ret.push_back(2);
dq.push_back(dq.front());
dq.pop_front();
}
return ret;
};
int main() {
int n; cin >> n;
cout << 2 << endl;
cout << "2 1";
for (int i = 3; i <= n; i++) cout << ' ' << i;
cout << endl;
cout << "1";
for (int i = 3; i <= n; i++) cout << ' ' << i;
cout << " 2";
cout << endl;
vector v(n + 1, 0);
for (int i = 1; i <= n; i++) cin >> v[i];
auto res = sol(n, v);
cout << res.size();
for (int x : res) cout << ' ' << x;
cout << endl;
}