// Artur Kraska, II UWr #include <bits/stdc++.h> #define forr(i, n) for(int i=0; i<n; i++) #define FOREACH(iter, coll) for(auto iter = coll.begin(); iter != coll.end(); ++iter) #define FOREACHR(iter, coll) for(auto iter = coll.rbegin(); iter != coll.rend(); ++iter) #define lbound(P,R,PRED) ({typeof(P) X=P,RRR=(R), PPP = P; while(PPP<RRR) {X = (PPP+(RRR-PPP)/2); if(PRED) RRR = X; else PPP = X+1;} PPP;}) #define testy() int _tests; scanf("%d", &_tests); FOR(_test, 1, _tests) #define CLEAR(tab) memset(tab, 0, sizeof(tab)) #define CONTAIN(el, coll) (coll.find(el) != coll.end()) #define FOR(i, a, b) for(int i=a; i<=b; i++) #define FORD(i, a, b) for(int i=a; i>=b; i--) #define MP make_pair #define PB push_back #define deb(X) X; #define M 1000000007 #define INF 1000000007LL #define G 1000003 #define D 1000004 #define L 1000005 #define P 1000006 using namespace std; int n, m, q, w, k, z, S, numery[17], dg[2200007], dd[2200007]; map <pair<int, int>, int> mapa_dg, mapa_lp; set <pair<int, int>> s, s_pion; struct elementy { int w, k; int gora, dol; // ustawic tu siebie na poczatku int upd_g, upd_d; }; elementy tab[1000017]; int znajdz_g(int nr) { nr += S; int res = dg[nr]; while(nr > 1) { if((nr&1) == 0) res = min(res, dg[nr+1]); // cout << "znajdz " << res << endl; nr >>= 1; } return res; } void wstaw_g(int nr, int ile) { // cout << "wklada na gorze, na pozycji " << nr << " wklada " << ile << endl; nr += S; // cout << nr << " -> " << dg[nr] << endl; dg[nr] = min(dg[nr], ile); nr >>= 1; while(nr > 1) { dg[nr] = min(dg[2*nr], dg[2*nr+1]); // cout << "wstaw " << dg[nr] << endl; nr >>= 1; } } int znajdz_d(int nr) { nr += S; int res = dd[nr]; while(nr > 1) { if((nr&1) == 1) res = max(res, dd[nr-1]); nr >>= 1; } return res; } void wstaw_d(int nr, int ile) { // cout << "wklada na dole, na pozycji " << nr << " wklada " << ile << endl; nr += S; dd[nr] = max(dd[nr], ile); nr >>= 1; while(nr > 1) { dd[nr] = max(dd[2*nr], dd[2*nr+1]); nr >>= 1; } } void wkladanie_g(int w, int k) { int gora; int ten = znajdz_g(w); if(ten > k && (ten == k+1 || (gora = znajdz_g(w-1)) <= k+1)) { wstaw_g(w, k); auto it = s.lower_bound(MP(w+1, k-1)); if(it->first == w+1) { wkladanie_g(it->first, it->second); } it = s_pion.lower_bound(MP(k-1, w+2)); it--; if(it->first == k-1) { // cout << "wkladajac " << w << ", " << k << " znalazl tez " << (it->second) << ", " << (it->first) << endl; wkladanie_g(it->second, it->first); } } } void wkladanie_d(int w, int k) { int dol; int ten = znajdz_d(w); if(ten < k) { if(ten == k-1 || (dol = znajdz_d(w+1)) >= k-1) { wstaw_d(w, k); auto it = s.lower_bound(MP(w-1, k+2)); it--; if(it->first == w-1) { wkladanie_d(it->first, it->second); } it = s_pion.lower_bound(MP(k+1, w-1)); if(it->first == k+1) { // cout << "wkladajac " << w << ", " << k << " znalazl tez " << (it->second) << ", " << (it->first) << endl; wkladanie_d(it->second, it->first); } } } } int main() { int x = 0; scanf("%d %d %d", &n, &m, &q); S = 1; while(S <= n+2) S *= 2; FOR(i, 0, S) { dg[i+S] = m+1; dd[i+S] = 0; } dg[S] = 1; dd[S+n+1] = m; FORD(i, S-1, 1) { dg[i] = min(dg[2*i], dg[2*i+1]); dd[i] = max(dd[2*i], dd[2*i+1]); } FOR(i, 1, q) { scanf("%d %d %d", &w, &k, &z); w = (w^x)%n; k = (k^x)%m; w++; k++; tab[q].w = w; tab[q].k = k; // cout << "bedzie wkladal " << w << " " << k << endl; // rozwazyc elementy na brzegach int gora = znajdz_g(w-1); int dol = znajdz_d(w+1); if(gora <= k+1 && dol >= k-1) { x ^= z; printf("TAK\n"); } else { printf("NIE\n"); s.insert(MP(w, k)); s_pion.insert(MP(k, w)); wkladanie_g(w, k); wkladanie_d(w, k); } /* cout << "drzewo gora:"; FOR(i, 0, n+1) cout << " " << znajdz_g(i); cout << endl; cout << "drzewo dol:"; FOR(i, 0, n+1) cout << " " << znajdz_d(i); cout << endl;*/ } 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 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | // Artur Kraska, II UWr #include <bits/stdc++.h> #define forr(i, n) for(int i=0; i<n; i++) #define FOREACH(iter, coll) for(auto iter = coll.begin(); iter != coll.end(); ++iter) #define FOREACHR(iter, coll) for(auto iter = coll.rbegin(); iter != coll.rend(); ++iter) #define lbound(P,R,PRED) ({typeof(P) X=P,RRR=(R), PPP = P; while(PPP<RRR) {X = (PPP+(RRR-PPP)/2); if(PRED) RRR = X; else PPP = X+1;} PPP;}) #define testy() int _tests; scanf("%d", &_tests); FOR(_test, 1, _tests) #define CLEAR(tab) memset(tab, 0, sizeof(tab)) #define CONTAIN(el, coll) (coll.find(el) != coll.end()) #define FOR(i, a, b) for(int i=a; i<=b; i++) #define FORD(i, a, b) for(int i=a; i>=b; i--) #define MP make_pair #define PB push_back #define deb(X) X; #define M 1000000007 #define INF 1000000007LL #define G 1000003 #define D 1000004 #define L 1000005 #define P 1000006 using namespace std; int n, m, q, w, k, z, S, numery[17], dg[2200007], dd[2200007]; map <pair<int, int>, int> mapa_dg, mapa_lp; set <pair<int, int>> s, s_pion; struct elementy { int w, k; int gora, dol; // ustawic tu siebie na poczatku int upd_g, upd_d; }; elementy tab[1000017]; int znajdz_g(int nr) { nr += S; int res = dg[nr]; while(nr > 1) { if((nr&1) == 0) res = min(res, dg[nr+1]); // cout << "znajdz " << res << endl; nr >>= 1; } return res; } void wstaw_g(int nr, int ile) { // cout << "wklada na gorze, na pozycji " << nr << " wklada " << ile << endl; nr += S; // cout << nr << " -> " << dg[nr] << endl; dg[nr] = min(dg[nr], ile); nr >>= 1; while(nr > 1) { dg[nr] = min(dg[2*nr], dg[2*nr+1]); // cout << "wstaw " << dg[nr] << endl; nr >>= 1; } } int znajdz_d(int nr) { nr += S; int res = dd[nr]; while(nr > 1) { if((nr&1) == 1) res = max(res, dd[nr-1]); nr >>= 1; } return res; } void wstaw_d(int nr, int ile) { // cout << "wklada na dole, na pozycji " << nr << " wklada " << ile << endl; nr += S; dd[nr] = max(dd[nr], ile); nr >>= 1; while(nr > 1) { dd[nr] = max(dd[2*nr], dd[2*nr+1]); nr >>= 1; } } void wkladanie_g(int w, int k) { int gora; int ten = znajdz_g(w); if(ten > k && (ten == k+1 || (gora = znajdz_g(w-1)) <= k+1)) { wstaw_g(w, k); auto it = s.lower_bound(MP(w+1, k-1)); if(it->first == w+1) { wkladanie_g(it->first, it->second); } it = s_pion.lower_bound(MP(k-1, w+2)); it--; if(it->first == k-1) { // cout << "wkladajac " << w << ", " << k << " znalazl tez " << (it->second) << ", " << (it->first) << endl; wkladanie_g(it->second, it->first); } } } void wkladanie_d(int w, int k) { int dol; int ten = znajdz_d(w); if(ten < k) { if(ten == k-1 || (dol = znajdz_d(w+1)) >= k-1) { wstaw_d(w, k); auto it = s.lower_bound(MP(w-1, k+2)); it--; if(it->first == w-1) { wkladanie_d(it->first, it->second); } it = s_pion.lower_bound(MP(k+1, w-1)); if(it->first == k+1) { // cout << "wkladajac " << w << ", " << k << " znalazl tez " << (it->second) << ", " << (it->first) << endl; wkladanie_d(it->second, it->first); } } } } int main() { int x = 0; scanf("%d %d %d", &n, &m, &q); S = 1; while(S <= n+2) S *= 2; FOR(i, 0, S) { dg[i+S] = m+1; dd[i+S] = 0; } dg[S] = 1; dd[S+n+1] = m; FORD(i, S-1, 1) { dg[i] = min(dg[2*i], dg[2*i+1]); dd[i] = max(dd[2*i], dd[2*i+1]); } FOR(i, 1, q) { scanf("%d %d %d", &w, &k, &z); w = (w^x)%n; k = (k^x)%m; w++; k++; tab[q].w = w; tab[q].k = k; // cout << "bedzie wkladal " << w << " " << k << endl; // rozwazyc elementy na brzegach int gora = znajdz_g(w-1); int dol = znajdz_d(w+1); if(gora <= k+1 && dol >= k-1) { x ^= z; printf("TAK\n"); } else { printf("NIE\n"); s.insert(MP(w, k)); s_pion.insert(MP(k, w)); wkladanie_g(w, k); wkladanie_d(w, k); } /* cout << "drzewo gora:"; FOR(i, 0, n+1) cout << " " << znajdz_g(i); cout << endl; cout << "drzewo dol:"; FOR(i, 0, n+1) cout << " " << znajdz_d(i); cout << endl;*/ } return 0; } |