#include <bits/stdc++.h> using namespace std; typedef const int cint; const int N = 100005; int my, mx, q, p, z; int px1 [N]; int px2 [N]; int py1 [N]; int py2 [N]; set <int> sx1 [N]; set <int> sx2 [N]; set <int> sy1 [N]; set <int> sy2 [N]; void rx1 (cint& x); void rx2 (cint& x); void ry1 (cint& y); void ry2 (cint& y); inline void put1 (cint& x, cint& y) { px1[x] = max(px1[x], y); py1[y] = min(py1[y], x); rx1(x); ry1(y); } void rx1 (cint& x) { int y; while (!sx1[x].empty() && *sx1[x].begin() <= px1[x]) { y = *sx1[x].begin(); sx1[x].erase(y); put1(x-1, y+1); } } void ry1 (cint& y) { int x; while (!sy1[y].empty() && *sy1[y].rbegin() >= py1[y]) { x = *sy1[y].rbegin(); sy1[y].erase(x); put1(x-1, y+1); } } inline void put2 (cint& x, cint& y) { px2[x] = min(px2[x], y); py2[y] = max(py2[y], x); rx2(x); ry2(y); } void rx2 (cint& x) { int y; while (!sx2[x].empty() && *sx2[x].rbegin() >= px2[x]) { y = *sx2[x].rbegin(); sx2[x].erase(y); put2(x+1, y-1); } } void ry2 (cint& y) { int x; while (!sy2[y].empty() && *sy2[y].begin() <= py2[y]) { x = *sy2[y].begin(); sy2[y].erase(x); put2(x+1, y-1); } } int main () { scanf ("%d%d%d", &my, &mx, &q); int x, y; for (x=0; x<mx; x++) { px1[x] = 0; px2[x] = my-1; } for (y=0; y<my; y++) { py1[y] = mx-1; py2[y] = 0; } px1[mx-1] = my-1; py1[0] = 0; px2[0] = 0; py2[my-1] = mx-1; while (q--) { scanf ("%d%d%d", &y, &x, &z); (y ^= p) %= my; (x ^= p) %= mx; if ((px1[x]>=y || py1[y]<=x) && (px2[x]<=y || py2[y]>=x)) { printf ("TAK\n"); p ^= z; continue; } sx1[x].insert(y); sx2[x].insert(y); sy1[y].insert(x); sy2[y].insert(x); rx1(x); rx2(x); ry1(y); ry2(y); printf ("NIE\n"); } return 0; }
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 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | #include <bits/stdc++.h> using namespace std; typedef const int cint; const int N = 100005; int my, mx, q, p, z; int px1 [N]; int px2 [N]; int py1 [N]; int py2 [N]; set <int> sx1 [N]; set <int> sx2 [N]; set <int> sy1 [N]; set <int> sy2 [N]; void rx1 (cint& x); void rx2 (cint& x); void ry1 (cint& y); void ry2 (cint& y); inline void put1 (cint& x, cint& y) { px1[x] = max(px1[x], y); py1[y] = min(py1[y], x); rx1(x); ry1(y); } void rx1 (cint& x) { int y; while (!sx1[x].empty() && *sx1[x].begin() <= px1[x]) { y = *sx1[x].begin(); sx1[x].erase(y); put1(x-1, y+1); } } void ry1 (cint& y) { int x; while (!sy1[y].empty() && *sy1[y].rbegin() >= py1[y]) { x = *sy1[y].rbegin(); sy1[y].erase(x); put1(x-1, y+1); } } inline void put2 (cint& x, cint& y) { px2[x] = min(px2[x], y); py2[y] = max(py2[y], x); rx2(x); ry2(y); } void rx2 (cint& x) { int y; while (!sx2[x].empty() && *sx2[x].rbegin() >= px2[x]) { y = *sx2[x].rbegin(); sx2[x].erase(y); put2(x+1, y-1); } } void ry2 (cint& y) { int x; while (!sy2[y].empty() && *sy2[y].begin() <= py2[y]) { x = *sy2[y].begin(); sy2[y].erase(x); put2(x+1, y-1); } } int main () { scanf ("%d%d%d", &my, &mx, &q); int x, y; for (x=0; x<mx; x++) { px1[x] = 0; px2[x] = my-1; } for (y=0; y<my; y++) { py1[y] = mx-1; py2[y] = 0; } px1[mx-1] = my-1; py1[0] = 0; px2[0] = 0; py2[my-1] = mx-1; while (q--) { scanf ("%d%d%d", &y, &x, &z); (y ^= p) %= my; (x ^= p) %= mx; if ((px1[x]>=y || py1[y]<=x) && (px2[x]<=y || py2[y]>=x)) { printf ("TAK\n"); p ^= z; continue; } sx1[x].insert(y); sx2[x].insert(y); sy1[y].insert(x); sy2[y].insert(x); rx1(x); rx2(x); ry1(y); ry2(y); printf ("NIE\n"); } return 0; } |