ქართული თარგმანი არ არის დამატებული

#include <cstring> using namespace std; inline void swap(int& a, int& b) { int tmp = a; a = b; b = tmp; } const int Blocksize = 100; const int Blockn = 15000 / Blocksize; int G[15000][3]; int block[Blockn][2][2]; int changed[Blockn]; inline void setg(int r1, int c1, int r2, int c2, int x) { if (c1 == c2) G[c1][2] = x; else { if (c1 > c2) swap(c1, c2); G[c1][r1] = x; } changed[c1 / Blocksize] = true; } inline void process(int start, int end, int& m1, int& m2) { for (int i = start; i < end; i++) { if (!m1 && !m2) break; if (G[i][2] && (m1 || m2)) m1 = m2 = 1; if (!G[i][0]) m1 = 0; if (!G[i][1]) m2 = 0; } } inline void makeblock(int x) { int start = Blocksize * x; int end = Blocksize * (x + 1); for (int t = 0; t < 2; t++) { int m1, m2; m1 = m2 = 0; if (!t) m1 = 1; else m2 = 1; process(start, end, m1, m2); block[x][t][0] = m1; block[x][t][1] = m2; } changed[x] = false; } inline bool answer(int r1, int c1, int r2, int c2) { if (c1 > c2) { swap(r1, r2); swap(c1, c2); } int b1 = c1 / Blocksize; int b2 = c2 / Blocksize; int m1, m2; m1 = m2 = 0; if (!r1) m1 = 1; else m2 = 1; if (b1 == b2) { process(c1, c2, m1, m2); } else { process(c1, (b1 + 1) * Blocksize, m1, m2); if (!m1 && !m2) return false; for (int i = b1 + 1; i < b2; i++) { if (changed[i]) makeblock(i); int newm1 = 0, newm2 = 0; if (m1 && block[i][0][0]) newm1 = 1; if (m1 && block[i][0][1]) newm2 = 1; if (m2 && block[i][1][0]) newm1 = 1; if (m2 && block[i][1][1]) newm2 = 1; m1 = newm1; m2 = newm2; if (!m1 && !m2) return false; } process(b2 * Blocksize, c2, m1, m2); } if (G[c2][2] && (m1 || m2)) m1 = m2 = 1; if ((r2 == 0 && m1) || (r2 == 1 && m2)) return true; else return false; } char line[100]; inline void solve() { while (1) { fgets(line, 100, stdin); if (line[0] == 'E') break; char cmd; int r1, c1, r2, c2; sscanf(line, "%c%d%d%d%d", &cmd, &r1, &c1, &r2, &c2); r1--; c1--; r2--; c2--; if (cmd == 'C') setg(r1, c1, r2, c2, 0); else if (cmd == 'O') setg(r1, c1, r2, c2, 1); else { bool ans = answer(r1, c1, r2, c2); if (ans) printf("Y\n"); else printf("N\n"); } } } inline void init() { memset(G, 0, sizeof G); for (int i = 0; i < Blockn; i++) changed[i] = true; FILE* fin = fopen("connect.in", "r"); int N; fscanf(fin, "%d", &N); for (int i = 0; i < N; i++) { int r1, c1, r2, c2; fscanf(fin, "%d%d%d%d", &r1, &c1, &r2, &c2); r1--; c1--; r2--; c2--; setg(r1, c1, r2, c2, 1); } } int main() { setlinebuf(stdout); init(); solve(); return 0; }

Powered By HBTech