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
|
#include<bits/stdc++.h> #define re register typedef long long ll; template<class T> inline void read(T &x) { x=0; char ch=getchar(),t=0; while(ch<'0'||ch>'9') t|=ch=='-',ch=getchar(); while(ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+(ch^48),ch=getchar(); if(t) x=-x; } template<class T,class ...T1> inline void read(T &x,T1 &...x1){ read(x),read(x1...); } template<class T> inline void write(T x) { if(x<0) putchar('-'),x=-x; if(x>9) write(x/10); putchar(x%10+'0'); } template<> inline void write(bool x){ putchar(x?'1':'0'); } template<> inline void write(char c){ putchar(c); } template<> inline void write(char *s){ while(*s!='\0') putchar(*s++); } template<> inline void write(const char *s){ while(*s!='\0') putchar(*s++); } template<class T,class ...T1> inline void write(T x,T1 ...x1){ write(x),write(x1...); } template<class T> inline bool checkMax(T &x,T y){ return x<y?x=y,1:0; } template<class T> inline bool checkMin(T &x,T y){ return x>y?x=y,1:0; } const int MAXN=5e2+10,MAXQ=6e5+10; int N,M,Q; std::bitset<MAXN>Pre[MAXN][MAXN],Suf[MAXN][MAXN]; char Mp[MAXN][MAXN]; struct query { int x1,x2,y1,y2,id; inline void readIn(int x){ read(x1,y1,x2,y2),id=x; } }Qry[MAXQ],T[MAXQ]; bool ans[MAXQ]; void conquer(int l,int r,int ql,int qr) { if(l>r||ql>qr) return ; int tl=ql-1,tr=qr+1; int mid=(l+r)>>1; for(int i=1;i<=M;++i) Pre[mid][i]=Suf[mid][i]=0; for(int i=M;i>=1;--i) if(Mp[mid][i]=='.') Pre[mid][i][i]=1,Pre[mid][i]|=Pre[mid][i+1]; for(int i=M;i>=1;--i) if(Mp[mid][i]=='.') Suf[mid][i][i]=1,Suf[mid][i]|=Suf[mid][i-1]; for(int x=mid-1;x>=l;--x) for(int y=M;y>=0;--y) if(Mp[x][y]=='.') Pre[x][y]=Pre[x+1][y]|Pre[x][y+1]; else Pre[x][y]=0; for(int x=mid+1;x<=r;++x) for(int y=1;y<=M;++y) if(Mp[x][y]=='.') Suf[x][y]=Suf[x-1][y]|Suf[x][y-1]; else Suf[x][y]=0; for(int i=ql;i<=qr;++i) { auto q=Qry[i]; if(q.x2<mid){ T[++tl]=q;continue; } if(q.x1>mid){ T[--tr]=q;continue; } ans[q.id]=(Pre[q.x1][q.y1]&Suf[q.x2][q.y2]).any(); } for(int i=ql;i<=tl;++i) Qry[i]=T[i]; for(int i=tr;i<=qr;++i) Qry[i]=T[i]; conquer(l,mid-1,ql,tl),conquer(mid+1,r,tr,qr); } int main() { read(N,M); for(int i=1;i<=N;++i) scanf("%s",Mp[i]+1); read(Q); for(int i=1;i<=Q;++i) Qry[i].readIn(i); conquer(1,N,1,Q); for(int i=1;i<=Q;++i) puts(ans[i]?"Yes":"No"); return 0; }
|