POJ 3264 Balanced Lineup (RMQ)

检验模板

代码:

#include 
#include 
#include 
#include 
#include 
using namespace std;

const int N = 200005;
int n, m;

int rmax[N][20], rmin[N][20], rmi[N], dp[N];

void rmqinit(int *A, int n) {
    rmi[0] = -1;
    for (int i = 1; i <= n; i++) {
        rmi[i] = ((i&(i - 1)) == 0) ? rmi[i - 1] + 1 : rmi[i - 1];
        rmax[i][0] = A[i];
        rmin[i][0] = A[i];
    }
    for (int j = 1; j <= rmi[n]; j++) {
        for (int i = 1; i + (1<



你可能感兴趣的:(数据结构-RMQ)