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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 #include using namespace std; typedef pair pii; const long long MSK=(1LL<<17),MX=1000100; const int dx[8]={-1,-1,-1,0,0,1,1,1}; const int dy[8]={-1,0,1,-1,1,-1,0,1}; int n,m,q,cur,cnt,xx,rx,cx,zx,x,y; bool side_a,side_b,bg; set sta,stb,v,w; pii rem[MX]; bool checksta(int x, int y) { //printf("check sta %d %d\n",x,y); if (sta.empty()) return true; auto it=sta.lower_bound({x-1,0}); if (it==sta.end()) return true; //printf(" checking: %d < %d = %d\n",y,it->second-1,y<(it->second-1)); return y<(it->second-1); } bool checkstb(int x, int y) { //printf("check stb %d %d\n",x,y); if (stb.empty()) return true; auto it=stb.upper_bound({x+1,m}); if (it==stb.begin()) return true; --it; //printf(" checking: %d > %d = %d\n",y,it->second+1,y>(it->second+1)); return y>(it->second+1); } void updsta(int x, int y) { //printf("upd sta %d %d\n",x,y); auto it=sta.lower_bound({x,0}); cnt=0; if (it!=sta.end()) { if (it->second<=y) return; if (it->first==x) rem[cnt++]=*it; } while (it!=sta.begin()) { --it; if (it->second>=y) rem[cnt++]=*it; } for (int j=0; j0) { it=w.upper_bound({y-1,x+1}); if (it!=w.begin()) { --it; if (it->first==y-1) { int xx=it->second; w.erase(it); v.erase({xx,y-1}); updsta(xx,y-1); if (xx>=x) return; } } } if (x+1first==x+1) { y=it->second; v.erase(it); w.erase({y,x+1}); updsta(x+1,y); } } } void updstb(int x, int y) { //printf("upd stb %d %d\n",x,y); auto it=stb.upper_bound({x,m}); if (it!=stb.begin()) { --it; if (it->second>=y) return; if (it->first==x) rem[cnt++]=*it; ++it; } while (it!=stb.end()) { if (it->second<=y) rem[cnt++]=*it; ++it; } for (int j=0; j0) { it=w.find({y,x-1}); if (it!=w.end()) { w.erase(it); v.erase({x-1,y}); updstb(x-1,y); return; } } if (y+1first==y+1) { int xx=it->second; w.erase(it); v.erase({xx,y+1}); updstb(xx,y+1); if (xx<=x) return; } } if (x>0) { it=v.lower_bound({x-1,y}); if (it!=v.begin()) { --it; if (it->first==x-1) { y=it->second; v.erase(it); w.erase({y,x-1}); updstb(x-1,y); } } } } int main() { scanf("%d%d%d",&n,&m,&q); sta.insert({-1,0}); sta.insert({n-1,m}); stb.insert({0,-1}); stb.insert({n,m-1}); for (cur=0; curfirst, it->second); puts(" <-sta"); //for (auto it=stb.begin(); it!=stb.end(); ++it) printf("(%d %d), ",it->first, it->second); puts(" <-stb"); //printf("%d: x=%d y=%d\n",cur,x,y); if (bg) { puts("TAK"); xx^=zx; } else puts("NIE"); } return 0; }