#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]);
}
}
}
void bitonicmerge(int l, int n, bool dir){
if (n == 1){
return;
}
int m = 1;
while (m * 2 < n){
m *= 2;
}
For(i, l, l + n - m){
compare(i, i + m, dir);
}
bitonicmerge(l, m, dir);
bitonicmerge(l + m, n - m, dir);
}
vector <tuple <int, int, bool>> vbitoniclayer[N];
void bitonicsort(int l, int n, bool dir, int depth = 0){
if (n == 1){
return;
}
vbitoniclayer[depth].emplace_back(l, n, dir);
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);
FordE(i, n, 0){
Fora(&arg, vbitoniclayer[i]){
bitonicmerge(get<0>(arg), get<1>(arg), get<2>(arg));
}
}
}
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();
random_shuffle(vidx);
answer(vidx);
}
Compilation message
swaps.cpp: In function 'void solve(int, int)':
swaps.cpp:128:24: error: no matching function for call to 'random_shuffle(vi&)'
128 | random_shuffle(vidx);
| ^
In file included from /usr/include/c++/10/algorithm:62,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
from swaps.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:4585:5: note: candidate: 'template<class _RAIter> void std::random_shuffle(_RAIter, _RAIter)'
4585 | random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last)
| ^~~~~~~~~~~~~~
/usr/include/c++/10/bits/stl_algo.h:4585:5: note: template argument deduction/substitution failed:
swaps.cpp:128:24: note: candidate expects 2 arguments, 1 provided
128 | random_shuffle(vidx);
| ^
In file included from /usr/include/c++/10/algorithm:62,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
from swaps.cpp:1:
/usr/include/c++/10/bits/stl_algo.h:4620:5: note: candidate: 'template<class _RAIter, class _Generator> void std::random_shuffle(_RAIter, _RAIter, _Generator&&)'
4620 | random_shuffle(_RandomAccessIterator __first, _RandomAccessIterator __last,
| ^~~~~~~~~~~~~~
/usr/include/c++/10/bits/stl_algo.h:4620:5: note: template argument deduction/substitution failed:
swaps.cpp:128:24: note: candidate expects 3 arguments, 1 provided
128 | random_shuffle(vidx);
| ^