L2-1 盲盒包装流水线

#include <iostream>
#include<algorithm>
#include<stack>
#include<vector>
using namespace std;
const int N = 1e6 + 50;
int book[100000] = { 0 };

int main() {

	int n;
	int size;
	cin >> n>>size;
	int temp;
	for (int i = 0; i < n; i++) {
		cin >> temp;
		book[temp] = i + 1;
	}
	stack<int>s;
	vector<int>a(n);
	int j = 0;
	for (int i = 1; i <= n; i++) {
		cin >> temp;
		s.push(temp);
		if (s.size() == size) {
			while (!s.empty()) {
				a[j] = s.top();
				s.pop();
				j++;
			}
		}
	}
	if (s.size() == size) {
		while (!s.empty()) {
			a[j] = s.top();
			s.pop();
			j++;
		}
	}
	int q;
	cin >> q;
	while (q--) {
		cin >> temp;
		if (book[temp] != 0) {
			cout << a[book[temp] - 1] << endl;
		}
		else cout << "Wrong Number\n";
	}
}