97382024-03-04 21:28:06anonLámpákcpp17Accepted 100/10059ms6012 KiB
#include <bits/stdc++.h>
#define FastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long long ll;
bool is_binomial_odd(ll n, ll k) {
    if(!k)
        return true;
    if((1 - n & 1) && (k & 1))
        return false;
    return is_binomial_odd(n / 2, k / 2);
}
int main() {
    FastIO;
    ll i, ans, N, K, Q, P, S;
    cin >> N >> K >> Q;
    vector<ll> D(N + 1);
    D[1] = 0;
    for(i = 2; i <= N; i++) {
        cin >> P;
        D[i] = D[P] + 1;
    }
    while(Q--) {
        cin >> ans;
        for(i = 2; i <= N; i++) {
            cin >> S;
            if(S && is_binomial_odd(D[i] + K - 1, D[i]))
                ans ^= 1;
        }
        cout << ans << '\n';
    }
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1824 KiB
2Accepted3ms2020 KiB
subtask215/15
3Accepted3ms2240 KiB
4Accepted19ms2680 KiB
5Accepted52ms4184 KiB
subtask310/10
6Accepted3ms2832 KiB
7Accepted3ms2924 KiB
8Accepted3ms2932 KiB
9Accepted3ms3160 KiB
10Accepted3ms3384 KiB
subtask430/30
11Accepted16ms3516 KiB
12Accepted16ms3496 KiB
13Accepted16ms3696 KiB
14Accepted16ms3832 KiB
15Accepted14ms4040 KiB
16Accepted16ms4256 KiB
17Accepted14ms4332 KiB
subtask545/45
18Accepted48ms4584 KiB
19Accepted52ms4516 KiB
20Accepted48ms4500 KiB
21Accepted52ms4496 KiB
22Accepted50ms4772 KiB
23Accepted57ms5936 KiB
24Accepted59ms5992 KiB
25Accepted57ms6000 KiB
26Accepted57ms6000 KiB
27Accepted59ms6012 KiB
28Accepted45ms4660 KiB
29Accepted45ms4652 KiB