This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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(m);
// cout << p.first << ' ' << p.second << ' ' << M.back() << '\n';
}
int c = 0;
int max_len = 0;
for(auto p: rang){
for(int i = p.first; i <= p.second; ++i){
if(M[c] == 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(B[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){
if(v[c].second == v[c].first){i++; c++; continue;}
for(int x: r.first) B[i] = x, i++;
B[i] = B[M[c]], i++;
for(int x: r.second) B[i++] = x, i++;
++c;
}
rang = v;
}
answer(B);
}
Compilation message (stderr)
swaps.cpp: In function 'void solve(int, int)':
swaps.cpp:54:13: warning: variable 'p' set but not used [-Wunused-but-set-variable]
54 | for(auto p: rang){
| ^
swaps.cpp:65:13: warning: variable 'p' set but not used [-Wunused-but-set-variable]
65 | for(auto p: rang){
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |