Codeforces 1073B Vasya and Books

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/polanwind/article/details/83653361

关键是记录数组元素的位置,然后暴力就行了。

#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;
}

猜你喜欢

转载自blog.csdn.net/polanwind/article/details/83653361