Question: Please help me fill in the range_sum_query function in C, below is the code. #include #include #define MAX_LEN 1024 * 1024 * 10 #define MAX_QUERIES
Please help me fill in the "range_sum_query" function in C, below is the code. #include#include #define MAX_LEN 1024 * 1024 * 10 #define MAX_QUERIES 1024 * 100 int range_sum_query(int a[], int n, int l, int r) { // WRITE YOUR CODE HERE // HINT: use binary search to find the boundry } // DO NOT MODIFY THE CODE BELOW int main() { int n, q; int left[MAX_QUERIES]; int right[MAX_QUERIES]; int result; int i; int *a; a = (int *)malloc(MAX_LEN * sizeof(int)); scanf("%d", &n); scanf("%d", &q); for (i = 0; i < n; i++) scanf("%d", &a[i]); for (i = 0; i < q; i++) { scanf("%d %d", &left[i], &right[i]); } for (i = 0; i < q; i++) { result = range_sum_query(a, n, left[i], right[i]); printf("%d ", result); } free(a); return 0; }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
