#include using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template bool chmax(T &a, const T &b) { if(a bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- int N,H,W; set S[1010]; int Y1[1010],Y2[1010],X1[1010],X2[1010]; template class UF { public: vector par,rank,cnt,G[um]; UF() {par=rank=vector(um,0); cnt=vector(um,1); for(int i=0;irank[y]) return par[x]=y; rank[x]+=rank[x]==rank[y]; return par[y]=x; } }; UF<1010*1010> uf; vector> V[1010]; int C[1010][1010]; int ret[1010]; void solve() { int i,j,k,l,r,x,y; string s; cin>>N>>H>>W; H+=2,W+=2; FOR(y,H) FOR(x,W) S[y].insert(x); int NW=H*W; FOR(i,N) { cin>>Y1[i]>>Y2[i]>>X1[i]>>X2[i]; for(y=Y1[i];y<=Y2[i];y++) { auto it=S[y].lower_bound(X1[i]); while(it!=S[y].end()&&*it<=X2[i]) { V[i].push_back({y,*it}); C[y][*it]=1; NW--; it=S[y].erase(it); } } } FOR(y,H) FOR(x,W) { if(C[y][x]==0&&y&&C[y-1][x]==0) uf(y*1010+x,(y-1)*1010+x); if(C[y][x]==0&&x&&C[y][x-1]==0) uf(y*1010+x,(y-0)*1010+x-1); } for(i=N-1;i>=0;i--) { ret[i]=uf.count(0)==NW; FORR2(y,x,V[i]) { C[y][x]=0; NW++; if(C[y-1][x]==0) uf(y*1010+x,(y-1)*1010+x); if(C[y+1][x]==0) uf(y*1010+x,(y+1)*1010+x); if(C[y][x-1]==0) uf(y*1010+x,(y-0)*1010+x-1); if(C[y][x+1]==0) uf(y*1010+x,(y-0)*1010+x+1); } } FOR(i,N) { if(ret[i]) cout<<"No"<