Codeforces 1073B——防自闭

版权声明:欢迎大家转载,转载请注明出处 https://blog.csdn.net/hao_zong_yin/article/details/83661028
#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int n, a[maxn], b[maxn], pos[maxn], vis[maxn];
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        pos[a[i]] = i;
    }
    memset(vis, 0, sizeof(vis));
    int l = 1;
    for (int i = 1; i <= n; i++) {
        scanf("%d", &b[i]);
        if (vis[b[i]]) printf("%d", 0);
        else {
            int p = pos[b[i]];
            printf("%d", p-l+1);
            for (int j = l; j <= p; j++) vis[a[j]] = 1;
            l = p+1;
        }
        if (i == n) printf("\n");
        else printf(" ");
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/hao_zong_yin/article/details/83661028