/* Test instructions: Give M,n a matrix with a length of m width to n, then give a Q for the number of queries, then each row of Q row gives a R1, C1, R2, C2 and meet (1 <= R1 <= R2 <= m, 1 <= C1 <= C2 < = N) outputs the maximum value in this rectangular range if the maximum is one of four vertices output yes otherwise output no*/#include <stdio.h> #include <math.h> #define MAX (A, B) a The definition of the >b?a:bint DP[305][305][9][9];//DP[X][Y][I][J]DP state is that the first two dimensions represent the horizontal ordinate, and the latter two dimensions represent the vertical axis on which the 2^i,j represents the ordinate 2^jint getmax (int a , int b,int c,int d) {int mx= (int) (log (c-a+1)/log (2)); int my= (int) (log (d-b+1)/log (2)); Return Max ((Max (dp[a][b][mx][my],dp[c-(1<<MX) +1][b][mx][my]), (Max (dp[a][d-(1<<my) +1][mx][my],dp[c- (1<<MX) +1][d-(1<<my) +1][mx][my])));} int dd (int a,int b,int c,int d,int maax) {if (Dp[a][b][0][0]==maax) return 1; if (DP[A][D][0][0]==MAAX) return 1; if (DP[C][B][0][0]==MAAX) return 1; if (DP[C][D][0][0]==MAAX) return 1; return 0;} int main () {int m,n; while (scanf ("%d%d", &n,&m)!=eof) {for (Int. I=1; i<=n; i++) for (int j=1; j<=m; j + +) scanf"%d", &dp[i][j][0][0]);//When i==j==0 dp[x][y][0][0] is the value of the point int mx= (int) (log (n)/log (2));//multiplication of the horizontal axis maximum range int my= (i NT) (log (M)/log (2));//The multiplier of the ordinate maximum range for (int i=0; i<=mx; i++) for (int j=0; j<=my; J + +) { if (i==0&&j==0)//When i==j==0 This is a point continue; for (int x=1; x+ (1<<i) -1<=n; x + +)//The following two-layer for loop whole is to iterate over the original two-dimensional map for (int y=1; y+ (1<<j) -1& Lt;=m; y++) {if (i==0) Dp[x][y][i][j]=max (dp[x][y][i][j-1],dp[x][y+ (1<< (j-1))][i] [J-1]); /When i==0 indicates that I control the range of 1 that is, the DP on each column is equivalent to the original one-dimensional rmq else Dp[x][y][i][j]=max (dp[x][y][i-1][j],dp[x+ (1<& lt; (i-1))][y][i-1][j]);/* When the i!=0 indicates that each column's DP already knows we divide the row into DP, it can be considered as a whole, the width of the line with X, y as the starting point is 2^i, and the vertical width is the maximum value of the rectangle. */}} scanf ("%d", &m); int a,b,c,d; for (int i=0;i<m;i++) {scanf ("%d%d%d%d", &a,&b,&c,&d); int Maax=getmax (A,B,C,D); printf ("%d%s\n", Maax,dd (A,b,c,d,maax)? " Yes ":" No "); }} return 0;} /*10 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 101 2 3 4 5 6 7 8 9 102 3 4 5 6 7 8 9 10 110010 1 10 10*/
HDU 2888 Check Corners