Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started