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);
M.pb(B[m]);
// cout << p.first << ' ' << p.second << ' ' << B[m] << '\n';
}
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(B[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], 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(Q[c].back());
Q[c].pop_back();
}else{
u[c].second.pb(Q[c].back());
Q[c].pop_back();
}
res.pop_back();
++c;
}
}
c = 0;
int i = 0;
for(auto r: u){
if(r.first.size() > 0) v.pb({i, i + r.first.size() - 1});
v.pb({i + r.first.size(), i + r.first.size()});
if(r.second.size() > 0) v.pb({i + r.first.size() + 1, i + r.first.size() + 1 + r.second.size() - 1});
for(int x: r.first) B[i] = x, i++;
B[i] = M[c], i++;
for(int x: r.second) B[i] = x, i++;
++c;
}
// cout << "B:";
// for(auto x: B) cout << x << ' ';
// en;
rang = v;
}
answer(B);
}
Compilation message (stderr)
swaps.cpp: In function 'void solve(int, int)':
swaps.cpp:51:13: warning: variable 'p' set but not used [-Wunused-but-set-variable]
51 | for(auto p: rang){
| ^
swaps.cpp:62:13: warning: variable 'p' set but not used [-Wunused-but-set-variable]
62 | 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... |