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;
int N;
vector<int> q;
//N 以上は小さい方が高い
void sch(int i,int j){
if(i<N&&j<N){
q.push_back(-1);
schedule(i+1,j+1);
}
else if(i<N){
q.push_back(1);
}
else if(j<N){
q.push_back(0);
}
else if(i<j){
q.push_back(1);
}
else{
q.push_back(0);
}
}
vector<int> my_visit(){
vector<int> r=visit();
vector<int> ret;
int i=0;
for(auto e:q){
if(e==-1){
ret.push_back(r[i]);
i++;
}
else{
ret.push_back(e);
}
}
q.clear();
return ret;
}
void solve(int n, int v) {
N=n;
//bitonic sort ですか?
int m=1;
int k=0;
while(m<n){
m*=2;
k++;
}
vector<int> a(m);
iota(a.begin(),a.end(),0);
for(int i=0;i<k;i++){
//前提条件:長さ 2^i のブロックは全てソート済み(奇数ブロック目は逆順ソート)
for(int j=i;j>=0;j--){
vector<pair<int,int>> s;
for(int k=0;k<m;k+=(1<<(j+1))){
for(int l=0;l<(1<<j);l++){
sch(a[k+l],a[k+l+(1<<j)]);
}
}
vector<int> r=my_visit();
int idx=0;
int rev=1;
for(int k=0;k<m;k+=(1<<(j+1))){
if(k%(1<<(i+1))==0) rev^=1;
for(int l=0;l<(1<<j);l++){
if((r[idx]^rev^1)){
swap(a[k+l],a[k+l+(1<<j)]);
}
idx++;
}
}
}
}
vector<int> ans;
for(int i=0;i<n;i++) ans.push_back(a[i]+1);
answer(ans);
}
# | 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... |