Input
Output
Sample Input
Sample Output
分析:先用RMQ預處理出最大值和最小值,然後進行dp即可。dp[i]表示1到i的最大威力和。
#include#include #include #include using namespace std; typedef __int64 LL; const int N = 1050; LL a[N]; LL dp[N]; LL Min[N][N], Max[N][N]; int n; LL RMQ_Init() { // 預處理出最大值和最小值 for(int i = 1; i <= n; i++) Min[i][0] = Max[i][0] = a[i]; for(int j = 1; (1< R) return 0; int k = 0; while((1<<(k+1)) <= R - L + 1) k++; return min(Min[L][k], Min[R - (1< R) return 0; int k = 0; while((1<<(k+1)) <= R - L + 1) k++; return max(Max[L][k], Max[R - (1<