过60%数据
#include<iostream>
using namespace std;
void quick_sort_down(int q[],int l,int r) {
if (l >= r) {
return;
}
int i = l - 1, j = r + 1, x = q[l + r >> 1];
while (i < j) {
do i++; while (q[i] > x);
do j--; while (q[j] < x);
if (i < j) {
swap(q[i], q[j]);
}
}
quick_sort_down(q, l, j);
quick_sort_down(q, j + 1, r);
}
void quick_sort_up(int q[],int l,int r) {
if (l >= r) {
return;
}
int i = l - 1, j = r + 1, x = q[l + r >> 1];
while (i < j) {
do i++; while (q[i] < x);
do j--; while (q[j] > x);
if (i < j) {
swap(q[i], q[j]);
}
}
quick_sort_up(q, l, j);
quick_sort_up(q, j + 1, r);
}
int main(){
int n,m;
cin>>n>>m;
int a[n];
for(int i=0;i<n;i++){
a[i]=i+1;
}
for(int i=0;i<m;i++){
int op,idx;
cin>>op>>idx;
if(op==0){
quick_sort_down(a,0,idx-1);
}
else quick_sort_up(a,idx-1,n-1);
}
for(int i=0;i<n;i++){
cout<<a[i]<<" ";
}
return 0;
}
全过
#include<iostream>
#include<deque>
using namespace std;
void quick_sort_down(int q[],int l,int r) {
if (l >= r) {
return;
}
int i = l - 1, j = r + 1, x = q[l + r >> 1];
while (i < j) {
do i++; while (q[i] > x);
do j--; while (q[j] < x);
if (i < j) {
swap(q[i], q[j]);
}
}
quick_sort_down(q, l, j);
quick_sort_down(q, j + 1, r);
}
void quick_sort_up(int q[],int l,int r) {
if (l >= r) {
return;
}
int i = l - 1, j = r + 1, x = q[l + r >> 1];
while (i < j) {
do i++; while (q[i] < x);
do j--; while (q[j] > x);
if (i < j) {
swap(q[i], q[j]);
}
}
quick_sort_up(q, l, j);
quick_sort_up(q, j + 1, r);
}
int main(){
int n,m;
cin>>n>>m;
int a[n];
for(int i=0;i<n;i++){
a[i]=i+1;
}
deque<pair<int,int>> q;
int op,idx;
cin>>op>>idx;
q.push_back({op,idx});
for(int i=1;i<m;i++){
int op,idx;
cin>>op>>idx;
if(op==q.back().first&&idx==q.back().second){
continue;
}
else q.push_back({op,idx});
}
for(int i=0;i<q.size();i++){
if(q[i].first==1){
quick_sort_up(a,q[i].second-1,n-1);
}
else{
quick_sort_down(a,0,q[i].second-1);
}
}
for(int i=0;i<n;i++){
cout<<a[i]<<" ";
}
return 0;
}
标签:sort,do,idx,int,蓝桥,while,quick,省赛,排序
From: https://www.cnblogs.com/wyf-fighting/p/16791150.html