#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define endl '\n'
#define fi first
#define se second
#define For(i, l, r) for (auto i = (l); i < (r); i++)
#define ForE(i, l, r) for (auto i = (l); i <= (r); i++)
#define FordE(i, l, r) for (auto i = (l); i >= (r); i--)
#define Fora(v, a) for (auto v: (a))
#define bend(a) (a).begin(), (a).end()
#define isz(a) ((signed)(a).size())
using ll = long long;
using ld = long double;
using pii = pair <int, int>;
using vi = vector <int>;
using vpii = vector <pii>;
using vvi = vector <vi>;
#include "swaps.h"
const int N = 5e2 + 5;
int n;
vi vidx;
bool built = 0;
vpii vschedule; vector <bool> vstartschedule; vi vansschedule; int ctrschedule;
void compare(int i, int j, bool dir){
if (!built){
vschedule.emplace_back(i, j);
}
else{
if (vstartschedule[ctrschedule]){
schedule(vidx[vschedule[ctrschedule].fi], vidx[vschedule[ctrschedule].se]);
int tctrschedule = ctrschedule + 1;
while (tctrschedule < isz(vschedule) and !vstartschedule[tctrschedule]){
schedule(vidx[vschedule[tctrschedule].fi], vidx[vschedule[tctrschedule].se]);
tctrschedule++;
}
vi cac = visit();
For(k, 0, isz(cac)){
vansschedule[ctrschedule + k] = cac[k];
}
}
if (dir == vansschedule[ctrschedule++]){
swap(vidx[i], vidx[j]);
}
}
}
vector <tuple <int, int, bool, int>> vbitoniclayer[N];
void bitonicmerge(int l, int n, bool dir, int depth){
if (n == 1){
return;
}
int m = 1;
while (m * 2 < n){
m *= 2;
}
For(i, l, l + n - m){
compare(i, i + m, dir);
}
vbitoniclayer[depth + 1].emplace_back(l, m, dir, depth + 1);
vbitoniclayer[depth + 1].emplace_back(l + m, n - m, dir, depth + 1);
// bitonicmerge(l, m, dir);
// bitonicmerge(l + m, n - m, dir);
}
void bitonicsort(int l, int n, bool dir, int depth){
if (n == 1){
return;
}
vbitoniclayer[depth].emplace_back(l, n, dir, depth);
int m = n / 2;
bitonicsort(l, m, !dir, depth + 1);
bitonicsort(l + m, n - m, dir, depth + 1);
// bitonicmerge(l, n, dir);
}
void reorder_merge(){
FordE(i, n, 0){
vbitoniclayer[i].clear();
}
bitonicsort(0, n, 0, 0);
while (1){
bool isempty = 1;
FordE(i, 20, 0){
if (vbitoniclayer[i].empty()){
continue;
}
Fora(&arg, vbitoniclayer[i]){
bitonicmerge(get<0>(arg), get<1>(arg), get<2>(arg), get<3>(arg));
}
vbitoniclayer[i].clear();
isempty = 0;
break;
}
if (isempty){
break;
}
}
}
void calschedule(){
vstartschedule.assign(isz(vschedule), 0);
vansschedule.assign(isz(vschedule), 0);
int i = 0;
while (i < isz(vschedule)){
vstartschedule[i] = 1;
set <int> stt;
while (i < isz(vschedule)){
if (stt.find(vschedule[i].fi) != stt.end() or stt.find(vschedule[i].se) != stt.end()){
break;
}
stt.insert(vschedule[i].fi); stt.insert(vschedule[i].se);
i++;
}
}
}
void solve(int _n, int v){
n = _n;
vidx.assign(n, 0);
For(i, 0, n){
vidx[i] = i + 1;
}
vschedule.clear(); vansschedule.clear(); ctrschedule = 0;
built = 0;
reorder_merge();
calschedule();
built = 1;
reorder_merge();
answer(vidx);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
2 ms |
384 KB |
Correct |
3 |
Correct |
5 ms |
328 KB |
Correct |
4 |
Correct |
9 ms |
556 KB |
Correct |
5 |
Correct |
9 ms |
548 KB |
Correct |
6 |
Correct |
7 ms |
552 KB |
Correct |
7 |
Correct |
8 ms |
548 KB |
Correct |
8 |
Correct |
7 ms |
552 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
2 ms |
328 KB |
Correct |
3 |
Correct |
3 ms |
328 KB |
Correct |
4 |
Correct |
6 ms |
548 KB |
Correct |
5 |
Correct |
8 ms |
672 KB |
Correct |
6 |
Correct |
8 ms |
556 KB |
Correct |
7 |
Correct |
9 ms |
548 KB |
Correct |
8 |
Correct |
8 ms |
608 KB |
Correct |
9 |
Correct |
8 ms |
548 KB |
Correct |
10 |
Correct |
8 ms |
556 KB |
Correct |
11 |
Correct |
8 ms |
556 KB |
Correct |
12 |
Correct |
9 ms |
552 KB |
Correct |
13 |
Correct |
7 ms |
552 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
2 ms |
328 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
2 ms |
328 KB |
Correct |
3 |
Correct |
1 ms |
200 KB |
Correct |
4 |
Correct |
2 ms |
328 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
2 ms |
328 KB |
Correct |
3 |
Correct |
4 ms |
408 KB |
Correct |
4 |
Correct |
7 ms |
548 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
2 ms |
328 KB |
Correct |
3 |
Correct |
4 ms |
408 KB |
Correct |
4 |
Correct |
7 ms |
548 KB |
Correct |
5 |
Correct |
1 ms |
200 KB |
Correct |
6 |
Correct |
2 ms |
328 KB |
Correct |
7 |
Correct |
3 ms |
412 KB |
Correct |
8 |
Correct |
9 ms |
552 KB |
Correct |
9 |
Correct |
8 ms |
548 KB |
Correct |
10 |
Correct |
10 ms |
548 KB |
Correct |
11 |
Correct |
7 ms |
548 KB |
Correct |
12 |
Correct |
10 ms |
552 KB |
Correct |
13 |
Correct |
1 ms |
200 KB |
Correct |
14 |
Correct |
2 ms |
328 KB |
Correct |
15 |
Correct |
3 ms |
328 KB |
Correct |
16 |
Correct |
8 ms |
548 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
2 ms |
328 KB |
Correct |
3 |
Correct |
3 ms |
408 KB |
Correct |
4 |
Correct |
7 ms |
552 KB |
Correct |
5 |
Correct |
8 ms |
548 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
2 ms |
328 KB |
Correct |
3 |
Correct |
3 ms |
408 KB |
Correct |
4 |
Correct |
7 ms |
552 KB |
Correct |
5 |
Correct |
8 ms |
548 KB |
Correct |
6 |
Correct |
1 ms |
200 KB |
Correct |
7 |
Correct |
2 ms |
328 KB |
Correct |
8 |
Correct |
3 ms |
328 KB |
Correct |
9 |
Correct |
7 ms |
552 KB |
Correct |
10 |
Correct |
7 ms |
548 KB |
Correct |
11 |
Correct |
10 ms |
552 KB |
Correct |
12 |
Correct |
7 ms |
552 KB |
Correct |
13 |
Correct |
7 ms |
552 KB |
Correct |
14 |
Correct |
7 ms |
552 KB |
Correct |
15 |
Correct |
7 ms |
544 KB |
Correct |
16 |
Correct |
8 ms |
668 KB |
Correct |
17 |
Correct |
11 ms |
552 KB |
Correct |
18 |
Correct |
8 ms |
548 KB |
Correct |
19 |
Correct |
1 ms |
200 KB |
Correct |
20 |
Correct |
2 ms |
328 KB |
Correct |
21 |
Correct |
3 ms |
328 KB |
Correct |
22 |
Correct |
7 ms |
552 KB |
Correct |
23 |
Correct |
8 ms |
528 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
2 ms |
328 KB |
Correct |
3 |
Correct |
4 ms |
328 KB |
Correct |
4 |
Correct |
7 ms |
560 KB |
Correct |
5 |
Correct |
6 ms |
552 KB |
Correct |
6 |
Correct |
9 ms |
532 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
2 ms |
328 KB |
Correct |
3 |
Correct |
4 ms |
328 KB |
Correct |
4 |
Correct |
7 ms |
560 KB |
Correct |
5 |
Correct |
6 ms |
552 KB |
Correct |
6 |
Correct |
9 ms |
532 KB |
Correct |
7 |
Correct |
1 ms |
292 KB |
Correct |
8 |
Correct |
2 ms |
328 KB |
Correct |
9 |
Correct |
3 ms |
408 KB |
Correct |
10 |
Correct |
8 ms |
548 KB |
Correct |
11 |
Correct |
8 ms |
548 KB |
Correct |
12 |
Correct |
7 ms |
548 KB |
Correct |
13 |
Correct |
7 ms |
552 KB |
Correct |
14 |
Correct |
7 ms |
556 KB |
Correct |
15 |
Correct |
7 ms |
552 KB |
Correct |
16 |
Correct |
9 ms |
548 KB |
Correct |
17 |
Correct |
7 ms |
548 KB |
Correct |
18 |
Correct |
11 ms |
548 KB |
Correct |
19 |
Correct |
7 ms |
536 KB |
Correct |
20 |
Correct |
1 ms |
200 KB |
Correct |
21 |
Correct |
2 ms |
328 KB |
Correct |
22 |
Correct |
3 ms |
328 KB |
Correct |
23 |
Correct |
7 ms |
548 KB |
Correct |
24 |
Correct |
7 ms |
536 KB |
Correct |
25 |
Correct |
8 ms |
528 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
2 ms |
328 KB |
Correct |
3 |
Correct |
4 ms |
416 KB |
Correct |
4 |
Correct |
9 ms |
548 KB |
Correct |
5 |
Correct |
10 ms |
528 KB |
Correct |
6 |
Correct |
8 ms |
524 KB |
Correct |
7 |
Correct |
8 ms |
524 KB |
Correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Correct |
2 |
Correct |
2 ms |
328 KB |
Correct |
3 |
Correct |
4 ms |
416 KB |
Correct |
4 |
Correct |
9 ms |
548 KB |
Correct |
5 |
Correct |
10 ms |
528 KB |
Correct |
6 |
Correct |
8 ms |
524 KB |
Correct |
7 |
Correct |
8 ms |
524 KB |
Correct |
8 |
Correct |
1 ms |
200 KB |
Correct |
9 |
Correct |
1 ms |
200 KB |
Correct |
10 |
Correct |
2 ms |
328 KB |
Correct |
11 |
Correct |
4 ms |
280 KB |
Correct |
12 |
Correct |
8 ms |
544 KB |
Correct |
13 |
Correct |
8 ms |
556 KB |
Correct |
14 |
Correct |
8 ms |
552 KB |
Correct |
15 |
Correct |
10 ms |
552 KB |
Correct |
16 |
Correct |
8 ms |
556 KB |
Correct |
17 |
Correct |
10 ms |
548 KB |
Correct |
18 |
Correct |
7 ms |
552 KB |
Correct |
19 |
Correct |
11 ms |
556 KB |
Correct |
20 |
Correct |
9 ms |
560 KB |
Correct |
21 |
Correct |
9 ms |
548 KB |
Correct |
22 |
Correct |
1 ms |
200 KB |
Correct |
23 |
Correct |
2 ms |
328 KB |
Correct |
24 |
Correct |
3 ms |
328 KB |
Correct |
25 |
Correct |
7 ms |
548 KB |
Correct |
26 |
Correct |
7 ms |
548 KB |
Correct |
27 |
Correct |
7 ms |
532 KB |
Correct |
28 |
Correct |
8 ms |
524 KB |
Correct |