86472024-01-24 19:27:35111Lámpákcpp11Accepted 100/10013ms26968 KiB
#include <bits/stdc++.h>
using namespace std;

bool incl(int a, int b) {
	// a includes b
	// CSES - Xor Pyramid
	return (a | b) == a;
}

char* pi = new char[10000000];

int ru() {
	while (!isdigit(*pi)) {
		pi++;
	}
	int x = 0;
	while (isdigit(*pi)) {
		x *= 10;
		x += *pi - '0';
		pi++;
	}
	return x;
}

int main() {
	fread(pi, 10000000, 1, stdin);
//	fread(pi, 10000000, 1, fopen("be2.txt", "r"));
	int N = ru(), K = ru(), Q = ru();
	vector<int> v(N + 1);
	for (int i = 2; i <= N; i++) {
		v[i] = ru();
	}
	vector<int> l(N + 1);
	for (int i = 2; i <= N; i++) {
		l[i] = l[v[i]] + 1;
	}
	while (Q--) {
		vector<int> w(N + 1);
		for (int i = 1; i <= N; i++) {
			w[i] = ru();
		}
		int ans = 0;
		for (int i = 1; i <= N; i++) {
			if (w[i]) {
				ans ^= incl(K - 1 + l[i], K - 1);
			}
		}
		cout << ans << '\n';
	}
	return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1812 KiB
2Accepted3ms2044 KiB
subtask215/15
3Accepted3ms2424 KiB
4Accepted6ms3804 KiB
5Accepted12ms8612 KiB
subtask310/10
6Accepted3ms4432 KiB
7Accepted3ms4760 KiB
8Accepted3ms4836 KiB
9Accepted3ms4792 KiB
10Accepted3ms4740 KiB
subtask430/30
11Accepted6ms5932 KiB
12Accepted6ms6048 KiB
13Accepted6ms6520 KiB
14Accepted6ms7044 KiB
15Accepted6ms7316 KiB
16Accepted6ms7760 KiB
17Accepted6ms8336 KiB
subtask545/45
18Accepted9ms11612 KiB
19Accepted9ms12980 KiB
20Accepted10ms14232 KiB
21Accepted9ms15228 KiB
22Accepted9ms16236 KiB
23Accepted12ms20280 KiB
24Accepted13ms21908 KiB
25Accepted12ms23752 KiB
26Accepted13ms25304 KiB
27Accepted13ms26968 KiB
28Accepted8ms24732 KiB
29Accepted8ms25928 KiB