Given two sequences of N integers consisting of both positive and negative integers inclusive 0 (sequence A and sequence B). Then there will be Q queries, in each, you will be given two integers l and r (r>=l). Let’s define a function:
The task is to print the value of Max(f(x, y)) – Min(f(x, y)) for each query.
Input: N = 5, Q = 2 A = 0 7 3 4 5 B = 0 3 1 2 3 l = 1, r = 1 l = 1, r = 3 Output: 0 917448 Input: N = 5, Q = 2 A = 0 -8 3 4 -9 B = 0 -3 -5 2 3 l = 1, r = 1 l = 1, r = 3 Output: 0 851916
Approach: If we clearly see the function only depends on the value of x and y which can be easily calculated by seeing the nature of the summation of the individual arrays. First, we precalculate the prefix sum of both the arrays and then we just see the nature of the summations. And always the value of x and y will either be 32766 or -32766 as we are taking the modulo of them.
Below is the implementation of the above approach:
- Find the maximum possible value of the minimum value of modified array
- Check if a given value can be reached from another value in a Circular Queue by K-length jumps
- Find minimum value of y for the given x values in Q queries from all the given set of lines
- Find the maximum value of Y for a given X from given set of lines
- Find the XOR of the elements in the given range [L, R] with the value K for a given set of queries
- Queries to increment array elements in a given range by a given value for a given number of times
- Only integer with positive value in positive negative value in array
- Find a Fixed Point (Value equal to index) in a given array
- Find four elements that sum to a given value | Set 1 (n^3 solution)
- Find k closest elements to a given value
- Find the smallest positive integer value that cannot be represented as sum of any subset of a given array
- Find minimum number of coins that make a given value
- Find maximum value of Sum( i*arr[i]) with only rotations on given array allowed
- Find four elements that sum to a given value | Set 3 (Hashmap)
- Find a Fixed Point (Value equal to index) in a given array | Duplicates Allowed
- Find value of (n^1 + n^2 + n^3 + n^4) mod 5 for given n
- Find the missing value from the given equation a + b = c
- Find number from given list for which value of the function is closest to A
- Find a pair from the given array with maximum nCr value
- Queries to find the maximum Xor value between X and the nodes of a given level of a perfect binary tree
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.