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 #include #include using namespace std; // bool v[5000+1][5000+1]; long long sciezka[200002]; vector > v; vector > kierunek; int main() { ios_base::sync_with_stdio(0); int k,n,m,r,c,z,x = 0; cin>>n>>m; v.resize(n+1, vector(m+1)); kierunek.resize(n+1, vector(m+1)); for(int i =0;i > q; vector< pair > cofnij; for(int i = 0; i <= m; i++)v[n][i]=true; for(int i = 0; i <= n; i++)v[i][m]=true; cin>>k; bool jest_na_sciezce = true; int pierwszy_przebieg = false; while(k--){ cin>>r>>c>>z; int rx = (r^x)%n; int cx = (c^x)%m; bool ok = false; if(pierwszy_przebieg){ long long w = (long long)rx*(long long)m+(long long)cx; long long *p = find(sciezka,sciezka+(n+m-1),w); if (p != sciezka+(n+m-1)){ jest_na_sciezce = true; }else{ jest_na_sciezce = false; ok = true; } } pierwszy_przebieg = true; v[rx][cx]=true; //fast weryfikacja if(jest_na_sciezce){ q.clear(); q.push_back(pair(0,0)); v[0][0]=true; cofnij.clear(); cofnij.push_back(pair(0,0)); while(!q.empty()){ pair p = q.back(); // cout<= n-1 && p.second >= m-1){ ok = true; break; } if(p.first >= n || p.second >= m){ ok = true; break; } q.pop_back(); if(!v[p.first][p.second+1]){ q.push_back(pair(p.first,p.second+1)); cofnij.push_back(pair(p.first,p.second+1)); v[p.first][p.second+1] = true; kierunek[p.first][p.second+1]=true; } if(!v[p.first+1][p.second]){ q.push_back(pair(p.first+1,p.second)); cofnij.push_back(pair(p.first+1,p.second)); v[p.first+1][p.second] = true; } } //aktualizuj_sciezke if(ok){ int xx = n-1; int yy = m-1; //wypisz_sciezke for(int i = 0;i>hh; // czyszcze } if(ok){ cout<<"NIE\n"; }else{ v[rx][cx]=false; x^=z; cout<<"TAK\n"; } } return 0; }