結果

問題 No.3726 Flawless Flow
コンテスト
ユーザー akua
提出日時 2026-09-28 11:18:40
言語 C++17
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++17 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 4,164 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,400 ms
コンパイル使用メモリ 216,040 KB
実行使用メモリ 9,904 KB
最終ジャッジ日時 2026-09-28 11:18:46
合計ジャッジ時間 5,517 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 48 WA * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define repi(i,a,b) for(ll i=(ll)(a); i<(ll)(b); i++)
using vi=vector<int>;
using vvi=vector<vi>;
using vll=vector<ll>;
using vvll=vector<vll>;
template<typename T,typename S> bool chmin(T&a,const S& b){
    return a>b?a=b,1:0;
}
template<typename T,typename S> bool chmax(T&a,const S& b){
    return a<b?a=b,1:0;
}
const ll inf=2e18;
#define all(a) (a).begin(),(a).end()
#define arr(a) (a).rbegin(),(a).rend()
using P=pair<ll,ll>;
using vp=vector<P>;
using vvp=vector<vp>;

struct UnionFind {
    vector<int> par,siz;
    UnionFind(int n) : par(n,-1),siz(n,1) {}
    int root(int x){
        if(par[x]==-1)return x;
        else return par[x]=root(par[x]);
    }
    bool issame(int x,int y){
        return root(x)==root(y);
    }
    bool unite(int x,int y){
        x=root(x),y=root(y);
        if(x==y)return false;
        if(siz[x]<siz[y])swap(x,y);
        par[y]=x;
        siz[x]+=siz[y];
        return true;
    }
    int size(int x){
        return siz[root(x)];
    }
};
constexpr int mod=998244353;
struct mint{
    int x;
    mint(ll x_=0) :x(x_%mod){
        if(x<0)x+=mod;
    }
    mint operator-(){
        auto res=*this;
        res.x=(x?mod-x:0);
        return res;
    }
    mint& operator+=(mint r){
        if((x+=r.x)>=mod)x-=mod;
        return *this;
    }
    mint& operator-=(mint r){
        if((x-=r.x)<0)x+=mod;
        return *this;
    }
    mint& operator*=(mint r){
        x=1LL*x*r.x%mod;
        return *this;
    }
    mint& operator/=(mint r){
        return *this*=r.inv();
    }
    friend mint operator+(mint a,mint b){
        return a+=b;
    }
    friend mint operator-(mint a,mint b){
        return a-=b;
    }
    friend mint operator*(mint a,mint b){
        return a*=b;
    }
    friend mint operator/(mint a,mint b){
        return a/=b;
    }
    mint inv() const{return pow(mod-2);}
    mint pow(ll b) const{
        mint a=*this,c=1;
        while(b){
            if(b&1)c*=a;
            a*=a;
            b>>=1;
        }
        return c;
    }
};
using vm=vector<mint>;
template<class S, S (*op)(S,S),S (*e)()> struct SegmentTree{
    private:
    int _n,size,log;
    vector<S> dat;
    void update(int k){
        dat[k]=op(dat[2*k],dat[2*k+1]);
    }
    public:
    SegmentTree():SegmentTree(0){}
    SegmentTree(int n):SegmentTree(vector<S>(n,e())){}
    SegmentTree(const vector<S>& v) : _n(int(v.size())){
        log=0;
        while((1<<log)<_n)log++;
        size=1<<log;
        dat=vector<S>(2*size,e());
        for(int i=0; i<_n; i++)dat[size+i]=v[i];
        for(int i=size-1; i>=1; i--){
            update(i);
        }
    }
    void set(int p,S x){
        p+=size;
        dat[p]=x;
        for(int i=1; i<=log; i++)update(p>>i);
    }
    S get(int p) const {return dat[p+size];}
    S prod(int l,int r) const{
        S sml=e(),smr=e();
        l+=size;
        r+=size;
        while(l<r){
            if(l&1)sml=op(sml,dat[l++]);
            if(r&1)smr=op(dat[--r],smr);
            l>>=1;
            r>>=1;
        }
    }
    S all_prod() const {return dat[1];}
};


void solve(int test){
    int n; cin >> n;
    vi a(n),b(n);
    rep(i,n)cin >> a[i],a[i]--;
    rep(i,n)cin >> b[i],b[i]--;
    vi invb(n);
    rep(i,n)invb[b[i]]=i;
    rep(i,n)cout <<a[i]+1 << " ";
    cout << endl;
    vi inva(n);
    rep(i,n)inva[a[i]]=i;
    rep(_,n-1){
        vi seen(n);
        for(auto v:b){
            if(seen[v])continue;
            if(inva[v]-1>=0){
                int u=a[inva[v]-1];
                if(!seen[u] && invb[u]>invb[v]){
                    int x=inva[u];
                    int y=inva[v];
                    swap(a[x],a[y]);
                    seen[u]=1;
                    seen[v]=1;
                    inva[a[x]]=x;
                    inva[a[y]]=y;
                }

            }
        }

        rep(i,n)cout << a[i]+1 << " ";
        cout << endl;
    }
    rep(i,n)cout << b[i]+1 << " ";
    cout << endl;





}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t=1; //cin >> t;
    rep(test,t)solve(test);
}



0