← 返回题目页

A1939 [USACO22FEB] Photoshoot 2 B

标程

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int &x : a) cin >> x;
    for (int &x : b) cin >> x;

    vector<char> placed(n + 1, 0);
    int p = 0, ans = 0;
    for (int k = 0; k < n; ++k) {
        while (placed[a[p]]) ++p;
        if (a[p] != b[k]) ++ans;
        placed[b[k]] = 1;
    }

    cout << ans << "\n";
    return 0;
}

动画演示