标签:
1 void RMQ(int num) 2 { 3 for(int j = 1; j < 20; ++j) 4 for(int i = 1; i <= num; ++i) 5 if(i + (1 << j) - 1 <= num) 6 { 7 maxsum[i][j] = max(maxsum[i][j - 1], maxsum[i + (1 << (j - 1))][j - 1]); 8 minsum[i][j] = min(minsum[i][j - 1], minsum[i + (1 << (j - 1))][j - 1]); 9 } 10 } 11 12 int getmax(int l, int r) { 13 int k = (int)(log((r-l+1)*1.0) / log(2.0)); 14 return max(maxsum[l][k], maxsum[r-(1<<k)+1][k]); 15 } 16 int getmin(int l, int r) { 17 int k = (int)(log((r-l+1)*1.0) / log(2.0)); 18 return min(minsum[l][k], minsum[r-(1<<k)+1][k]); 19 }
标签:
原文地址:http://www.cnblogs.com/mitrenick/p/4726292.html