跳到正文

个人记录

mmm

intandlonglong约 2 分钟
原文
文章信息与版本

文章信息

收录
2026年7月22日
更新
2026年7月22日
篇幅
约 2 分钟

版本

  1. v1当前
C++
#include <bits/stdc++.h>
using namespace std;
struct node{
    int x,id;
}a[100005],b[100005];
char c;
int n,na[100005],nb[100005];
map<int,int> ma,mb;
bool cmp(node x,node y){
    return x.x<y.x;
}
void dfs(int x,int y,int p,int q){
    if(x>y||p>q)return;
    int i=ma[na[x]];
    dfs(x+1,x+i-p,p,i-1);
    dfs(x+i-p+1,y,i+1,q);
    cout<<na[x]<<' ';
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i].x;
        ma[a[i].id]=i;
        a[i].id=i;
        na[i]=a[i].x;
    }
    for(int i=1;i<=n;i++){
        cin>>b[i].x;
        mb[b[i].id]=ma[b[i].id];
        b[i].id=i;
        nb[i]=b[i].id;
    }
    sort(a+1,a+n+1,cmp);
    sort(b+1,b+n+1,cmp);
    for(int i=1;i<=n;i++)
        ma[a[i].x]=b[i].id;
    dfs(1,n,1,n);
    return 0;
}
原文