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>
#define sz(a) (int)(a.size())
#define pb push_back
using namespace std;
int nn,pw = 1;
vector<int>v;
void bitonic(int n){
if(n==1)return;
int z = n/2;
for(int i=0;i<pw;i+=2*z){
for(int j=i;j<i+z;j++){
if(max(v[j],v[j+z]) <= nn)schedule(v[j],v[j+z]);
}
}
vector<int>res = visit();
int k = 0;
for(int i=0;i<pw;i+=2*z){
for(int j=i;j<i+z;j++){
if(max(v[j],v[j+z]) <= nn){
if(!res[k])swap(v[j],v[j+z]);
k++;
}else if(v[j] >nn)swap(v[j],v[j+z]);
}
}
bitonic(n/2);
}
void merge(int n){
if(n==1)return;
merge(n/2);
int z = n/2;
for(int i=0;i<pw;i+=2*z){
for(int j=i;j<i+z;j++){
if(max(v[j],v[j+z]) <= nn)schedule(v[j],v[j+z]);
}
}
vector<int>res = visit();
int k = 0;
for(int i=0;i<pw;i+=2*z){
for(int j=i+z;j<i+2*z;j++){
int inv = j-i-z;
inv = z-inv-1;
inv = i+z+inv;
if(inv > j)swap(v[j],v[inv]);
}
}
bitonic(n);
}
void solve(int n,int V){
nn = n;
while(pw<n)pw*=2;
for(int i=1;i<=pw;i++)v.push_back(i);
merge(pw);
vector<int>fin;
for(int x:v)if(x<=n)fin.pb(x);
answer(fin);
}
Compilation message (stderr)
swaps.cpp: In function 'void merge(int)':
swaps.cpp:40:6: warning: unused variable 'k' [-Wunused-variable]
40 | int k = 0;
| ^
# | 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... |