#include<iostream>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<sstream>
#include<string>
#include<climits>
#include<stack>
#include<set>
#include<bitset>
#include<cmath>
#include<deque>
#include<map>
#include<queue>
#define iinf 2000000000
#define linf 1000000000000000000LL
#define dinf 1e200
#define eps 1e-5
#define all(v) (v).begin(),(v).end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define lng long long
#define sqr(a) ((a)*(a))
#define pii pair<int,int>
#define pll pair<lng,lng>
#define pss pair<string,string>
#define pdd pair<double,double>
#define X first
#define Y second
#define pi 3.14159265359
#define ff(i,xi,n) for(int i=xi;i<=(int)(n);++i)
#define ffd(i,xi,n) for(int i=xi;i>=(int)(n);--i)
#define ffl(i,r) for(int i=head[r];i!=-1;i=edge[i].next)
#define cc(i,j) memset(i,j,sizeof(i))
#define two(x) ((lng)1<<(x))
#define N 333
#define M 1000000
#define lson l , mid , rt << 1
#define rson mid + 1 , r , rt << 1 | 1
#define Mod n
#define Pmod(x) (x%Mod+Mod)%Mod
using namespace std;
typedef vector<int> vi;
typedef vector<string> vs;
typedef unsigned int uint;
typedef unsigned lng ulng;
template<class T> inline void checkmax(T &x,T y){if(x<y) x=y;}
template<class T> inline void checkmin(T &x,T y){if(x>y) x=y;}
template<class T> inline T Min(T x,T y){return (x>y?y:x);}
template<class T> inline T Max(T x,T y){return (x<y?y:x);}
template<class T> T gcd(T a,T b){return (a%b)==0?b:gcd(b,a%b);}
template<class T> T lcm(T a,T b){return a*b/gcd(a,b);}
template<class T> T Abs(T a){return a>0?a:(-a);}
template<class T> inline T lowbit(T n){return (n^(n-1))&n;}
template<class T> inline int countbit(T n){return (n==0)?0:(1+countbit(n&(n-1)));}
template<class T> inline bool isPrimeNumber(T n)
{if(n<=1)return false;for (T i=2;i*i<=n;i++) if (n%i==0) return false;return true;}
int Map[N][N],ma[N][10][N][10],m,n;
int main()
{
while(scanf("%d%d",&m,&n)==2)
{
int q;
ff(i,1,m)
ff(j,1,n)
{scanf("%d",&Map[i][j]);
ma[i][0][j][0]=Map[i][j];
}
for(int j=0,z1=(log((double)m)/log(2.0));j<=z1;++j)
for(int k=0,z2=(log((double)n)/log(2.0));k<=z2;++k)
{
if(j==0&&k==0) continue;
int jx=(j-1),ky=(k-1);
int lenx,leny;
if(jx<0) jx=j,lenx=0;else lenx=two(jx);
if(ky<0) ky=k,leny=0; else leny=two(ky);
for(int x=1,zx=m-two(j)+1;x<=zx;++x)
for(int y=1,zy=n-two(k)+1;y<=zy;++y)
ma[x][j][y][k]=Max(Max(ma[x][jx][y][ky],ma[x+lenx][jx][y][ky]),Max(ma[x][jx][y+leny][ky],ma[x+lenx][jx][y+leny][ky]));
}
scanf("%d",&q);
ff(i,1,q)
{
int x1,x2,y1,y2;
scanf("%d%d%d%d",&x1,&y1,&x2,&y2);
int val;
int jx,jy,lenx,leny;
lenx=log((double)(x2-x1+1))/log(2.0),leny=log((double)(y2-y1+1))/log(2.0);
jx=x2-two(lenx)+1,jy=y2-two(leny)+1;
val=Max(Max(ma[x1][lenx][y1][leny],ma[jx][lenx][y1][leny]),Max(ma[x1][lenx][jy][leny],ma[jx][lenx][jy][leny]));
printf("%d %s\n",val,(val==Map[x1][y1]||val==Map[x2][y2]||val==Map[x1][y2]||val==Map[x2][y1])?"yes":"no");
}
}
return 0;
}
hdu 2888 二维rmq
最新推荐文章于 2020-08-24 20:50:00 发布