結果

問題 No.1115 二つの数列 / Two Sequences
ユーザー uw_yu1rabbit
提出日時 2020-12-20 21:33:12
言語 C++17(gcc12)
(gcc 12.3.0 + boost 1.87.0)
結果
TLE  
実行時間 -
コード長 1,114 bytes
コンパイル時間 2,751 ms
コンパイル使用メモリ 101,716 KB
最終ジャッジ日時 2025-01-17 04:59:27
ジャッジサーバーID
(参考情報)
judge2 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 19 TLE * 16
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cstdint>
#include<cstddef>
#include<vector>
//#include<atcoder/all>
//using namespace atcoder;
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = size_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
template<typename T>
using vec = vector<T>;
#define rep(i, n) for (i64 i = 0; i < (i64)(n); ++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;
void solve(){
}
int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    u64 n;
    cin >> n;
    vec<u64> a(n),b(n);
    vec<u64> id(n);
    rep(i,n){
        cin >> a[i];
        a[i]--;
        id[a[i]] = i;
    }
    rep(i,n){
        cin >> b[i];
        b[i]--;
    }
    u64 ans = 0;
    rep(i,n){
        u64 now = id[b[i]];
        while(a[i] != b[i]){
                ans++;
                swap(a[now],a[now - 1]);
                now--;
                id[a[now + 1]] = now + 1;
        }
    }
    cout << ans << endl;
}
0