// C++ program to do range minimum query in O(1) time with // O(n Log n) extra space and O(n Log n) preprocessing time #include using namespace std; #define MAX 500 // lookup[i][j] is going to store index of minimum value in // arr[i..j]. Ideally lookup table size should not be fixed and // should be determined using n Log n. It is kept constant to // keep code simple. int lookup[MAX][MAX]; // Structure to represent a query range struct Query { int L, R; }; // Fills lookup array lookup[][] in bottom up manner. void preprocess(int arr[], int n) { // Initialize M for the intervals with length 1 for (int i = 0; i < n; i++) lookup[i][0] = i; // Compute values from smaller to bigger intervals for (int j=1; (1< arr[lookup[i + (1<<(j-1))][j-1]]) lookup[i][j] = lookup[i][j-1]; else lookup[i][j] = lookup[i + (1 << (j-1))][j-1]; } } } // Returns minimum of arr[L..R] int query(int arr[], int L, int R) { // For [2,10], j = 3 int j = (int)log2(R-L+1); // For [2,10], we compare arr[lookup[0][3]] and // arr[lookup[3][3]], if (arr[lookup[L][j]] >= arr[lookup[R - (1< &v, int L, int R) { int i, array[10006]; for (i = 0; i < v.size(); i++) { array[i] = v[i]; } return RMQ(array, v.size(), L, R); } int main() { int n; cin>>n; int a[n]; for(int i=0;i>a[i]; } long int sum=0; int u=0; //int *b; int b[10006]; vectorv; for(int k=0;k