#include<bits/stdc++.h>
using namespace std;
int hblock[100009];
int vblock[100009];
int hgreatwall = -1;
int vgreatwall = -1;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m, k;
cin >> n >> m >> k;
fill(hblock, hblock + n + 6, m + 9);
fill(vblock, vblock + m + 6, n + 9);
int r, c, z;
int n1, m1;
int x = 0;
int oldhbl, oldvbl, oldhgw, oldvgw;
for(int i = 0; i < k; i++) {
cin >> r >> c >> z;
n1 = (r^x)%n;
m1 = (c^x)%m;
oldhbl = hblock[n1];
oldvbl = vblock[m1];
oldhgw = hgreatwall;
oldvgw = vgreatwall;
hblock[n1] = min(hblock[n1], m1);
vblock[m1] = min(vblock[m1], n1);
int curr = n1;
while((hgreatwall == curr - 1) and (hblock[curr] >= hblock[curr-1] - 1) and (hblock[curr] <= m)) {
hgreatwall++;
curr++;
}
curr = m1;
while((vgreatwall == curr - 1) and (vblock[curr] >= vblock[curr-1] - 1) and (vblock[curr] <= n)) {
vgreatwall++;
curr++;
}
if(hgreatwall >= n - 1 or vgreatwall >= m - 1 or ((vgreatwall >= 0 and vblock[vgreatwall] <= hgreatwall) and (hgreatwall >= 0 and hblock[hgreatwall] <= vgreatwall))) {
hgreatwall = oldhgw;
vgreatwall = oldvgw;
hblock[n1] = oldhbl;
vblock[m1] = oldvbl;
x ^= z;
cout << "TAK\n";
}
else {
cout << "NIE\n";
}
}
}
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 50 51 52 53 54 55 | #include<bits/stdc++.h> using namespace std; int hblock[100009]; int vblock[100009]; int hgreatwall = -1; int vgreatwall = -1; int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, m, k; cin >> n >> m >> k; fill(hblock, hblock + n + 6, m + 9); fill(vblock, vblock + m + 6, n + 9); int r, c, z; int n1, m1; int x = 0; int oldhbl, oldvbl, oldhgw, oldvgw; for(int i = 0; i < k; i++) { cin >> r >> c >> z; n1 = (r^x)%n; m1 = (c^x)%m; oldhbl = hblock[n1]; oldvbl = vblock[m1]; oldhgw = hgreatwall; oldvgw = vgreatwall; hblock[n1] = min(hblock[n1], m1); vblock[m1] = min(vblock[m1], n1); int curr = n1; while((hgreatwall == curr - 1) and (hblock[curr] >= hblock[curr-1] - 1) and (hblock[curr] <= m)) { hgreatwall++; curr++; } curr = m1; while((vgreatwall == curr - 1) and (vblock[curr] >= vblock[curr-1] - 1) and (vblock[curr] <= n)) { vgreatwall++; curr++; } if(hgreatwall >= n - 1 or vgreatwall >= m - 1 or ((vgreatwall >= 0 and vblock[vgreatwall] <= hgreatwall) and (hgreatwall >= 0 and hblock[hgreatwall] <= vgreatwall))) { hgreatwall = oldhgw; vgreatwall = oldvgw; hblock[n1] = oldhbl; vblock[m1] = oldvbl; x ^= z; cout << "TAK\n"; } else { cout << "NIE\n"; } } } |
English