There is a matrix, each query a sub-matrix, to determine whether the maximum value of this sub-matrix is not in the four corners of this sub-matrix
Bare two-dimensional RMQ
1 #pragmaComment (linker, "/stack:1677721600")2#include <map>3#include <Set>4#include <stack>5#include <queue>6#include <cmath>7#include <ctime>8#include <vector>9#include <cstdio>Ten#include <cctype> One#include <cstring> A#include <cstdlib> -#include <iostream> -#include <algorithm> the using namespacestd; - #defineINF 0x3f3f3f3f - #defineInf (-((LL) 1<<40)) - #defineLson k<<1, L, (L + R) >>1 + #defineRson k<<1|1, ((L + R) >>1) + 1, R - #defineMem0 (a) memset (A,0,sizeof (a)) + #defineMem1 (a) memset (A,-1,sizeof (a)) A #defineMem (A, B) memset (A, B, sizeof (a)) at #defineFIN freopen ("In.txt", "R", stdin) - #defineFOUT freopen ("OUT.txt", "w", stdout) - #defineRep (I, A, b) for (int i = A; I <= B; i + +) - #defineDec (i, A, b) for (int i = A; I >= b; i-) - -template<classT> T MAX (t A, T b) {returna > B?a:b;} intemplate<classT> T MIN (t A, T b) {returnA < b?a:b;} -template<classT> T GCD (t A, T b) {returnB? GCD (b, a%b): A; } totemplate<classT> T LCM (t A, T b) {returnA/GCD (A, b) *b; } + - //typedef __int64 LL; thetypedefLong LongLL; * Const intMAXN =50000+ -; $ Const intMAXM =110000;Panax Notoginseng Const DoubleEPS = 1e-8; -LL MOD =1000000007; the + intm, N; A intmx[302][9][302][9]; the intidx[302], q, LX, ly, Rx, ry; + - voidRmq_init (intMintN) { $ for(inti =0; (1<<i) <= m; i + +) { $ for(intj =0; (1<<J) <= N; J + +) { - if(i = =0&& J = =0)Continue; - intLen2 = (1<< j), Len1 = (1<<i); the for(intx =1; X + len1-1<= m; X + +) { - for(inty =1; Y + len2-1<= N; Y + +) {Wuyi if(i = =0) Mx[x][i][y][j] = max (Mx[x][i][y][j-1], Mx[x][i][y + (Len2 >>1)][j-1]); the ElseMX[X][I][Y][J] = max (Mx[x][i-1][Y][J], mx[x + (Len1 >>1)][i-1][y][j]); - } Wu } - } About } $ for(inti =1; I <= m | | I <= N; i + +) { -Idx[i] =0; - while((1<< (Idx[i] +1))) <= i) idx[i] + +; - } A } + the intRmqintLxintRxintLyintry) { - intA = IDX[RX-LX +1], La = (1<<a); $ intb = idx[ry-ly +1], LB = (1<<b); the returnMax (max ( mx[lx][a][ly][b), theMx[rx-la +1][a][ly][b]), theMX[LX][A][RY-LB +1][b]), theMx[rx-la +1][A][RY-LB +1][b]); - } in the intMain () the { About //FIN; the while(~SCANF ("%d%d", &m, &N)) { the mem0 (MX); theRep (I,1, M) Rep (J,1, N) +scanf"%d", &mx[i][0][j][0]); - Rmq_init (M, n); thescanf"%d", &q);Bayi while(q--) { thescanf"%d %d%d%d", &LX, &ly, &rx, &ry); the intMa =RMQ (LX, rx, Ly, ry); -printf"%d%s\n", MA, MA = = mx[lx][0][ly][0] || Ma = = mx[lx][0][ry][0] -|| Ma = = mx[rx][0][ly][0] || Ma = = mx[rx][0][ry][0] the?"Yes":"No"); the } the } the return 0; -}
HDU2888 Check Corners (two-dimensional RMQ)