#include #include #include #include #include #include #define mod 1000000007 using namespace std; typedef long long lint; int n,m; int direction[4][2] = {{-1,0}, {1,0}, {0,-1}, {0,1}}; int visited[1003][1003]; bool bfs(int &startX, int &startY, int &x1, int &y1, int &x2, int &y2, vector> &mtx){ queue,pair>> q; q.push({{startX, startY},{1, 1}}); visited[startX][startY] = 1; int area = 1; int lastXCount = 1; int lastYCount = 1; while(!q.empty()){ int x = q.front().first.first; int y = q.front().first.second; int xCount = q.front().second.first; int yCount = q.front().second.second; q.pop(); //cout << "x:" << x << "y:" << y << endl; for(int i=0; i<4; i++){ int newX = x + direction[i][0]; int newY = y + direction[i][1]; if(newX<0 or newXx2 or newX>=n) continue; if(newY<0 or newYy2 or newY>=m) continue; if(mtx[newX][newY] == 1 and visited[newX][newY] == 0){ if(newX != x){ xCount++; } if(newY != y){ yCount++; } q.push({{newX, newY},{xCount, yCount}}); visited[newX][newY] = 1; lastXCount = xCount; lastYCount = yCount; area++; } } } cout << "are:" <> n >> m; vector> mtx(n, vector(m)); for(int i=0; i> mtx[i][j]; } } int q; cin >> q; for(int i=0; i> type; if(type == 1){ int x,y; cin >> x >> y; mtx[x-1][y-1] = !mtx[x-1][y-1]; }else{ int x1,y1,x2,y2; cin >> x1 >> y1 >> x2 >> y2; x1 -= 1; y1 -= 1; x2 -= 1; y2 -= 1; memset(visited, 0, sizeof visited); bool flag = false; for(int x=x1; x<=x2; x++){ for(int y=y1; y<=y2; y++){ if(!visited[x][y] and mtx[x][y] == 1){ flag = bfs(x,y,x1,y1,x2,y2,mtx); if(flag) break; } } if(flag) break; } cout << (flag ? "YES":"NO") << endl; } } return 0; }