#include "monster.h"
#include <bits/stdc++.h>
using namespace std;
vector<int> Solve(int n)
{
vector<int> ord(n);
iota(ord.begin(), ord.end(), 0);
function<void(int, int)> solve = [&](int l, int r)
{
if (l == r - 1)
{
return;
}
int mid = (l + r) / 2;
solve(l, mid);
solve(mid, r);
int i = l, j = mid;
vector<int> res;
while (i < mid && j < r)
{
if (!Query(ord[i], ord[j]))
{
res.push_back(ord[i]);
i++;
}
else
{
res.push_back(ord[j]);
j++;
}
}
while (i < mid)
{
res.push_back(ord[i]);
i++;
}
while (j < r)
{
res.push_back(ord[j]);
j++;
}
for (int k = l; k < r; k++)
{
ord[k] = res[k - l];
}
};
solve(0, n);
auto solve4 = [&]()
{
if (Query(ord[0], ord[3]))
{
swap(ord[0], ord[2]);
}
else if (Query(ord[1], ord[3]))
{
swap(ord[1], ord[2]);
}
else
{
swap(ord[0], ord[1]);
}
};
auto solve6 = [&]()
{
for (int i = 0; i < 3; i++)
{
for (int j = 3; j < 6; j++)
{
if (Query(ord[i], ord[j]))
{
swap(ord[2], ord[i]);
swap(ord[3], ord[j]);
goto found;
}
}
}
found:
if (Query(ord[0], ord[2]))
{
swap(ord[0], ord[1]);
}
if (Query(ord[3], ord[5]))
{
swap(ord[4], ord[5]);
}
};
auto get = [&]() -> int
{
if (!Query(ord[0], ord[2]))
{
int j = 3;
while (j < n && !Query(ord[0], ord[j]))
{
j++;
}
if (Query(ord[1], ord[j]))
{
reverse(ord.begin() + 1, ord.begin() + j + 1);
}
else
{
swap(ord[0], ord[1]);
reverse(ord.begin() + 2, ord.begin() + j + 1);
}
return j + 1;
}
if (Query(ord[0], ord[3]))
{
if (Query(ord[1], ord[3]))
{
int j = 4;
while (j < n && Query(ord[1], ord[j]))
{
j++;
}
reverse(ord.begin(), ord.begin() + j);
return j;
}
}
if (n == 4)
{
solve4();
return 4;
}
if (n == 5)
{
swap(ord[3], ord[4]);
solve4();
return 5;
}
if (n == 6)
{
solve6();
return 6;
}
if (!Query(ord[3], ord[5]))
{
int j = 6;
while (j < n && !Query(ord[3], ord[j]))
{
j++;
}
if (Query(ord[4], ord[j]))
{
reverse(ord.begin() + 4, ord.begin() + j + 1);
}
else
{
swap(ord[3], ord[4]);
reverse(ord.begin() + 5, ord.begin() + j + 1);
}
solve4();
return j + 1;
}
if (Query(ord[3], ord[6]))
{
if (Query(ord[4], ord[6]))
{
int j = 7;
while (j < n && Query(ord[4], ord[j]))
{
j++;
}
reverse(ord.begin() + 3, ord.begin() + j);
solve4();
return j;
}
}
solve6();
return 6;
};
int i = get();
while (i < n)
{
int j = i;
while (j < n && !Query(ord[i - 1], ord[j]))
{
j++;
}
reverse(ord.begin() + i, ord.begin() + j + 1);
i = j + 1;
}
vector<int> ans(n);
for (int i = 0; i < n; i++)
{
ans[ord[i]] = i;
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
7 ms |
436 KB |
Output is correct |
17 |
Correct |
5 ms |
600 KB |
Output is correct |
18 |
Correct |
8 ms |
436 KB |
Output is correct |
19 |
Correct |
6 ms |
596 KB |
Output is correct |
20 |
Correct |
6 ms |
600 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
4 ms |
600 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
3 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Correct |
0 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
0 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
344 KB |
Output is correct |
16 |
Correct |
7 ms |
436 KB |
Output is correct |
17 |
Correct |
5 ms |
600 KB |
Output is correct |
18 |
Correct |
8 ms |
436 KB |
Output is correct |
19 |
Correct |
6 ms |
596 KB |
Output is correct |
20 |
Correct |
6 ms |
600 KB |
Output is correct |
21 |
Correct |
0 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
344 KB |
Output is correct |
23 |
Correct |
0 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
4 ms |
600 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
0 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
3 ms |
600 KB |
Output is correct |
33 |
Correct |
42 ms |
596 KB |
Output is correct |
34 |
Correct |
49 ms |
676 KB |
Output is correct |
35 |
Correct |
40 ms |
428 KB |
Output is correct |
36 |
Correct |
42 ms |
592 KB |
Output is correct |
37 |
Correct |
55 ms |
600 KB |
Output is correct |
38 |
Correct |
48 ms |
600 KB |
Output is correct |
39 |
Correct |
41 ms |
600 KB |
Output is correct |
40 |
Correct |
45 ms |
420 KB |
Output is correct |
41 |
Correct |
36 ms |
440 KB |
Output is correct |
42 |
Correct |
32 ms |
436 KB |
Output is correct |
43 |
Correct |
30 ms |
600 KB |
Output is correct |
44 |
Correct |
29 ms |
600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
592 KB |
Output is correct |
2 |
Correct |
38 ms |
600 KB |
Output is correct |
3 |
Correct |
41 ms |
600 KB |
Output is correct |
4 |
Correct |
42 ms |
444 KB |
Output is correct |
5 |
Correct |
43 ms |
600 KB |
Output is correct |
6 |
Correct |
41 ms |
436 KB |
Output is correct |
7 |
Correct |
42 ms |
500 KB |
Output is correct |
8 |
Correct |
41 ms |
424 KB |
Output is correct |
9 |
Correct |
36 ms |
848 KB |
Output is correct |
10 |
Correct |
57 ms |
848 KB |
Output is correct |
11 |
Correct |
40 ms |
600 KB |
Output is correct |
12 |
Correct |
46 ms |
596 KB |
Output is correct |
13 |
Correct |
43 ms |
668 KB |
Output is correct |
14 |
Correct |
39 ms |
600 KB |
Output is correct |
15 |
Correct |
25 ms |
600 KB |
Output is correct |
16 |
Correct |
20 ms |
600 KB |
Output is correct |
17 |
Correct |
44 ms |
416 KB |
Output is correct |
18 |
Correct |
27 ms |
600 KB |
Output is correct |