pi只有0~5000且只找最小的没出现的,又要找不同club的,考虑二分匹配,左边pi,右边ci,一个匹配一个。离线倒着加边即可。

const int maxn = 5e3 + 5;
int m, n, d, now;
int P[maxn], C[maxn], K[maxn];
int match[maxn], ans[maxn];
bool mark[maxn], used[maxn];
vector<int> G[maxn];

bool dfs(int cur) {
	if (used[cur])	return false;
	used[cur] = 1;
	for (auto to : G[cur]) {
		if (match[to] == -1 || dfs(match[to])) {
			match[to] = cur;
			return true;
		}
	}
	return false;
}

int main() {
	read(m), read(n);
	rep(i, 1, m)	read(P[i]);
	rep(i, 1, m)	read(C[i]);
	read(d);
	rep(i, 1, d) {
		read(K[i]);
		mark[K[i]] = true;
	}
	rep(i, 1, m) {
		if (!mark[i]) {
			G[P[i]].push_back(C[i]);
		}
	}

	init(match, -1);
	irep(i, d, 1) {
		init(used, 0);
		while (dfs(now)) {
			now++;
			init(used, 0);
		}

		ans[i] = now;
		int t = K[i];
		G[P[t]].push_back(C[t]);
	}

	rep(i, 1, d)	writeln(ans[i]);
	return 0;
}