// #include <swaps.h>
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
void schedule(int, int);
vector<int> visit();
void answer(std::vector<int>);
vector<int> B;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
void solve(int N, int V){
for(int i = 1; i <= N; ++i) B.pb(i);
vector<pair<int, int>> rang;
rang.pb({0, N - 1});
int mx = N-1;
while(mx > 0){
vector<pair<int, int>> v;
vector<vector<int>> Q(rang.size());
vector<pair<vector<int>, vector<int>>> u(rang.size());
vector<int> M;
for(auto p: rang){
int m = uniform_int_distribution<int> (p.first, p.second) (rng);
if(p.first < m) v.pb({p.first, m - 1});
v.pb({m, m});
if(p.second > m) v.pb({m + 1, p.second});
M.pb(B[m]);
}
int c = 0;
int max_len = 0;
for(auto p: rang){
for(int i = p.first; i <= p.second; ++i){
if(M[c] == B[i]) continue;
Q[c].pb(i);
// cout << "q" << i << ' ';
}
max_len = max(max_len, p.second - p.first);
++c;
}
mx = max_len;
for(int i = 0; i < max_len; ++i){
int c = 0;
for(auto p: rang){
if(Q[c].empty()){
++c;
continue;
}
schedule(M[c], B[Q[c].back()]);
++c;
}
c = 0;
vector<int> res = visit();
reverse(all(res));
for(auto p: rang){
if(Q[c].empty()) {
++c;
continue;
}
if(res.back()){
u[c].first.pb(B[Q[c].back()]);
Q[c].pop_back();
}else{
u[c].second.pb(B[Q[c].back()]);
Q[c].pop_back();
}
res.pop_back();
++c;
}
}
c = 0;
int i = 0;
for(auto r: u){
for(int x: r.first) B[i] = x, i++;
B[i] = M[c], i++;
for(int x: r.second) B[i] = x, i++;
++c;
}
rang = v;
}
reverse(all(B));
answer(B);
}
Compilation message
swaps.cpp: In function 'void solve(int, int)':
swaps.cpp:53:13: warning: variable 'p' set but not used [-Wunused-but-set-variable]
53 | for(auto p: rang){
| ^
swaps.cpp:64:13: warning: variable 'p' set but not used [-Wunused-but-set-variable]
64 | for(auto p: rang){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Not correct |
2 |
Halted |
0 ms |
0 KB |
- |