1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
| #include <bits/stdc++.h> #define sz(x) (int)x.size() #define mp make_pair using namespace std; int main() { int n, k, q, d; scanf("%d%d%d%d", &n, &k, &q, &d); vector<vector<int>> L(k, vector<int>(n)); for(int i=0; i<k; i++) for(int j=0; j<n; j++) scanf("%d", &L[i][j]); vector<vector<pair<int,pair<int,int>>>> M(k); for(int i=0; i<n; i++) M[k-1].push_back(mp(L[k-1][i], mp(i, 0))); for(int i=k-2; i>=0; i--) { int a = 0, b = 1; while(a<n && b<sz(M[i+1])) { if(L[i][a]<=M[i+1][b].first) M[i].push_back(mp(L[i][a], mp(a, b))), a++; else M[i].push_back(mp(M[i+1][b].first, mp(a, b))), b += 2; } while(a<n) M[i].push_back(mp(L[i][a], mp(a, b))), a++; while(b<sz(M[i+1])) M[i].push_back(mp(M[i+1][b].first, mp(a, b))), b += 2; } int lstans = 0; for(int _=1; _<=q; _++) { int x; scanf("%d", &x); x ^= lstans; int p = lower_bound(M[0].begin(), M[0].end(), mp(x, mp(0, 0))) - M[0].begin(); int curans = 0, idx = 0; while(idx<k && p<sz(M[idx])) { if(M[idx][p].second.first<n) curans ^= L[idx][M[idx][p].second.first]; if(idx<k-1) { int nxtp = M[idx][p].second.second; if(nxtp-1<sz(M[idx+1]) && M[idx+1][nxtp-1].first>=x) --nxtp; p = nxtp; } ++idx; } lstans = curans; if(_%d==0) printf("%d\n", curans); } return 0; }
|