1. 程式人生 > >Codeforces 1073B Vasya and Books

Codeforces 1073B Vasya and Books

關鍵是記錄陣列元素的位置,然後暴力就行了。

#define  _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <algorithm>
#include <deque>
#include <iostream>
#include <string>
#include <math.h>

using namespace std;

int n;
int temp1[2 * 100000 + 5];
int temp2[2 * 100000 + 5];
int temp3[2 * 100000 + 5];

int main() {
	scanf("%d", &n);
	for (int i = 1;i <= n;++i) {
		scanf("%d", &temp1[i]);
		temp3[temp1[i]] = i;
	}
	for (int i = 1;i <= n;++i) {
		scanf("%d", &temp2[i]);
	}
	for (int i = 1;i <= n;++i) {
		if (temp1[temp3[temp2[i]]]) {
			for (int j = temp3[temp2[i]];j >= 0;--j) {
				if (temp1[j]) {
					temp1[j] = 0;
				}
				else {
					printf("%d ", temp3[temp2[i]] - j);
					break;
				}
			}
		}
		else {
			printf("0 ");
		}
	}
	//system("pause");
	return 0;
}