#include "monster.h"
#include<bits/stdc++.h>
using namespace std;
namespace {
#define vec vector
#define arr array
#define pb push_back
void quick_sort(vec<int>& v, int l0, int r0, int ri = -1, int rn = -1) {
if(v.size() == 0) return;
vec<int> left(0);
vec<int> right(0);
bool nr = ri==-1;
while(ri == rn || ri == -1) {
ri = rand()%v.size();
ri = v[ri];
}
for(int i = 0; i<v.size(); i++) {
if(v[i]==ri) continue;
if(Query(ri, v[i])) {
left.pb(v[i]);
}
else {
right.pb(v[i]);
}
}
pair<int, int> nxtl;
pair<int, int> nxtr;
int si = -1;
bool sn = false;
if(left.size() < l0) {
int ll0 = left.size();
nxtl = {ll0, 0};
int lr0 = l0-(left.size()+1);
nxtr = {lr0, r0};
}
else if(right.size() < r0) {
int rr0 = right.size();
nxtr = {0, rr0};
int rl0 = r0-(right.size()+1);
nxtl = {l0, rl0};
}
else if(v.size()-l0-r0 == 2) {
if(left.size() > l0) {
assert(left.size() == l0+1);
nxtl = {l0, 1};
nxtr = {0, r0};
si = -2;
}
else {
assert(right.size() == r0+1);
nxtl = {l0, 0};
nxtr = {1, r0};
si = 2;
}
}
else if(left.size() == l0) {
assert(right.size() == r0);
nxtl = {l0, 0};
nxtr = {0, r0};
}
else if(nr && left.size() == l0+1) {
quick_sort(v, l0, r0, left.back());
return;
}
else if(nr && right.size() == r0+1) {
quick_sort(v, l0, r0, right.front());
return;
}
else {
nxtl = {l0, 1};
nxtr = {1, r0};
sn = true;
}
int lftsz = left.size()-(nxtl.first+nxtl.second);
int rightsz = right.size()-(nxtr.first+nxtr.second);
if(lftsz==3 || rightsz==3) {
quick_sort(v, l0, r0, -1, ri);
return;
}
quick_sort(left, nxtl.first, nxtl.second);
quick_sort(right, nxtr.first, nxtr.second);
if(si == -2) {
swap(left[left.size()-1], ri);
}
else if(si == 2) {
swap(right[0], ri);
}
if(sn) {
swap(right[0], left[left.size()-1]);
}
vec<int> res = left;
res.pb(ri);
for(int i = 0; i<right.size(); i++) res.pb(right[i]);
// cerr << "RES-------------" << '\n';
// for(int i = 0; i<res.size(); i++) cerr << res[i] << ' ';
// cerr << '\n';
v = res;
}
}
std::vector<int> Solve(int n) {
std::vector<int> v(n);
for (int i = 0; i < n; i++) v[i] = i;
quick_sort(v, 0, 0);
std::vector<int> res(n);
for(int i = 0; i<n; i++) {
res[v[i]] = i;
}
return res;
}
Compilation message
monster.cpp: In function 'void {anonymous}::quick_sort(std::vector<int>&, int, int, int, int)':
monster.cpp:24:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | for(int i = 0; i<v.size(); i++) {
| ~^~~~~~~~~
monster.cpp:39:18: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
39 | if(left.size() < l0) {
| ~~~~~~~~~~~~^~~~
monster.cpp:46:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
46 | else if(right.size() < r0) {
| ~~~~~~~~~~~~~^~~~
monster.cpp:54:19: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
54 | if(left.size() > l0) {
| ~~~~~~~~~~~~^~~~
In file included from /usr/include/c++/10/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
from monster.cpp:2:
monster.cpp:55:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
55 | assert(left.size() == l0+1);
| ~~~~~~~~~~~~^~~~~~~
monster.cpp:62:25: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
62 | assert(right.size() == r0+1);
| ~~~~~~~~~~~~~^~~~~~~
monster.cpp:68:23: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
68 | else if(left.size() == l0) {
| ~~~~~~~~~~~~^~~~~
In file included from /usr/include/c++/10/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
from monster.cpp:2:
monster.cpp:69:24: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
69 | assert(right.size() == r0);
| ~~~~~~~~~~~~~^~~~~
monster.cpp:73:29: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
73 | else if(nr && left.size() == l0+1) {
| ~~~~~~~~~~~~^~~~~~~
monster.cpp:77:30: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
77 | else if(nr && right.size() == r0+1) {
| ~~~~~~~~~~~~~^~~~~~~
monster.cpp:109:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
109 | for(int i = 0; i<right.size(); i++) res.pb(right[i]);
| ~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 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 |
0 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 |
13 ms |
856 KB |
Output is correct |
17 |
Correct |
10 ms |
1112 KB |
Output is correct |
18 |
Correct |
8 ms |
600 KB |
Output is correct |
19 |
Correct |
7 ms |
696 KB |
Output is correct |
20 |
Correct |
7 ms |
856 KB |
Output is correct |
21 |
Correct |
1 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 |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
9 ms |
604 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
7 ms |
1112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 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 |
0 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 |
13 ms |
856 KB |
Output is correct |
17 |
Correct |
10 ms |
1112 KB |
Output is correct |
18 |
Correct |
8 ms |
600 KB |
Output is correct |
19 |
Correct |
7 ms |
696 KB |
Output is correct |
20 |
Correct |
7 ms |
856 KB |
Output is correct |
21 |
Correct |
1 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 |
0 ms |
344 KB |
Output is correct |
25 |
Correct |
0 ms |
344 KB |
Output is correct |
26 |
Correct |
9 ms |
604 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
1 ms |
344 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
7 ms |
1112 KB |
Output is correct |
33 |
Correct |
70 ms |
1208 KB |
Output is correct |
34 |
Correct |
57 ms |
1216 KB |
Output is correct |
35 |
Correct |
75 ms |
1360 KB |
Output is correct |
36 |
Correct |
69 ms |
956 KB |
Output is correct |
37 |
Correct |
69 ms |
1204 KB |
Output is correct |
38 |
Correct |
58 ms |
1128 KB |
Output is correct |
39 |
Correct |
60 ms |
876 KB |
Output is correct |
40 |
Correct |
70 ms |
688 KB |
Output is correct |
41 |
Correct |
69 ms |
856 KB |
Output is correct |
42 |
Correct |
59 ms |
1200 KB |
Output is correct |
43 |
Correct |
45 ms |
1116 KB |
Output is correct |
44 |
Correct |
66 ms |
964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Partially correct |
67 ms |
1384 KB |
Partially correct |
2 |
Partially correct |
57 ms |
1116 KB |
Partially correct |
3 |
Partially correct |
69 ms |
696 KB |
Partially correct |
4 |
Partially correct |
65 ms |
1380 KB |
Partially correct |
5 |
Partially correct |
76 ms |
868 KB |
Partially correct |
6 |
Partially correct |
80 ms |
1112 KB |
Partially correct |
7 |
Partially correct |
82 ms |
980 KB |
Partially correct |
8 |
Partially correct |
53 ms |
868 KB |
Partially correct |
9 |
Partially correct |
98 ms |
952 KB |
Partially correct |
10 |
Partially correct |
65 ms |
716 KB |
Partially correct |
11 |
Partially correct |
65 ms |
848 KB |
Partially correct |
12 |
Partially correct |
52 ms |
856 KB |
Partially correct |
13 |
Incorrect |
119 ms |
2016 KB |
Wrong Answer [6] |
14 |
Halted |
0 ms |
0 KB |
- |