[hdu2888] Two-dimensional RMQ

Source: Internet
Author: User

Test instructions: The maximum value in the rectangle is obtained. Two-dimensional rmq.

1 #pragmaComment (linker, "/stack:10240000,10240000")2 3#include <iostream>4#include <cstdio>5#include <algorithm>6#include <cstdlib>7#include <cstring>8#include <map>9#include <queue>Ten#include <deque> One#include <cmath> A#include <vector> -#include <ctime> -#include <cctype> the#include <Set> -  - using namespacestd; -  + #defineMem0 (a) memset (a, 0, sizeof (a)) - #defineLson L, M, RT << 1 + #defineRson m + 1, R, RT << 1 | 1 A #definedefine_m int m = (L + r) >> 1 at #defineRep (A, b) for (int a = 0; a < b; a++) - #defineLowbit (x) ((x) & (-(x))) - #defineCONSTRUCTINT4 (name, a, B, C, D) name (int a = 0, int b = 0, int c = 0, int d = 0): A (a), B (b), C (c), D (d) {} - #defineCONSTRUCTINT3 (name, a, B, c) name (int a = 0, int b = 0, int c = 0): A (a), B (b), C (c) {} - #defineConstructInt2 (name, a, b) name (int a = 0, int b = 0): A (a), B (b) {} -  intypedefDoubledb; -typedefLong LongLL; totypedef pair<int,int>PII; +typedef multiset<int>MSI; -typedef multiset<int>:: iterator msii; thetypedefSet<int>si; *typedefSet<int>:: iterator sii; $typedef vector<int>VI;Panax Notoginseng  - Const intdx[8] = {1,0, -1,0,1,1, -1, -1}; the Const intdy[8] = {0, -1,0,1, -1,1,1, -1}; + Const intMAXN = 1e5 +7; A Const intMAXM = 1e5 +7; the Const intMAXV = 1e7 +7; + Const intMD = 1e9 +7; - Const intINF = 1e9 +7; $ Const DoublePI = ACOs (-1.0); $ Const DoubleEPS = 1e-Ten; -  - inta[ -][ -], t[301], f[ -][9][ -][9], N, m; the  - voidinit_rmq () {Wuyi      for(inti =0; I < n; i++) { the          for(intj =0; J < M; J + +) { -f[i][0][j][0] =A[i][j]; Wu         } -     } About      for(intDX =0; DX <=8; dx++) { $          for(intDY =0; Dy <=8; dy++) { -             if(dx = =0&& dy = =0)Continue; -              for(inti =0; i + (1<< dx) <= n; i++) { -                  for(intj =0; J + (1<< dy) <= m; J + +) { A                    int&p =F[i][dx][j][dy]; +                     if(dx) p = max (F[I][DX-1][j][dy], F[i + (1<< (DX-1))][DX-1][j][dy]); the                     Elsep = max (F[i][dx][j][dy-1], F[i][dx][j + (1<< (Dy-1))][dy-1]); -                 } $             } the         } the     } the } the  - intRMQ (intX1,intY1,intX2,inty2) { in     intL1 = t[x2-x1 +1], L2 = t[y2-y1 +1]; the     returnMax (F[x1][l1][y1][l2], Max (F[x1][l1][y2-(1<< L2) +1][l2], theMax (F[X2-(1<< L1) +1][L1][Y1][L2], f[x2-(1<< L1) +1][l1][y2-(1<< L2) +1][l2] )); About } the  the intMain () { the     //freopen ("In.txt", "R", stdin); +      for(inti =1; I <= -; i++) { -         intj =0; the          while((1<< (j +1)) <= i) J + +;BayiT[i] =J; the     } the     intx1, x2, y1, y2, q; -      while(Cin >> N >>m) { -          for(inti =0; I < n; i++) { the              for(intj =0; J < M; J + +) { thescanf"%d", &a[i][j]); the             } the         } - init_rmq (); theCIN >>Q; the          for(inti =0; i < Q; i++) { thescanf"%d%d%d%d", &x1, &y1, &AMP;X2, &y2);94x1--; x2--; y1--; y2--; the             intres =RMQ (x1, y1, x2, y2); theprintf"%d", res); the             if(A[x1][y1] = = Res | | a[x2][y1] = = Res | | a[x1][y2] = = Res | | a[x2][y2] = = res) puts ("Yes");98             ElsePuts"No"); About         } -     }101     return 0;102}
View Code

[hdu2888] Two-dimensional RMQ

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.