Home /
Expert Answers /
Computer Science /
please-write-a-code-to-solve-the-following-problem-in-c-also-explain-the-code-do-please-read-the-pa253
(Solved): Please Write a code to solve the following problem in C. Also, Explain the code. Do Please read the ...
Please Write a code to solve the following problem in C. Also, Explain the code. Do Please read the "Note" Given to understand the restrictions to solve the problem. Thanks
NOTE: the easy and the hard version of the problem vary on the basis of the constraints given. Use of any other libraries apart from "stdio.h" is not allowed. Otherwise, your submission will not be graded. Lawrence has bought N cupcakes for Kone. But it turns out that Kone doesn't want to eat them. Kone will eat the cupcakes only if Lawrence solves the problem given by him. Kone arranges the cupcakes in a row and assigns a random value Ai? to the ith cupcake. The values assigned to the cupcakes will be given to you in the form of an array A. He asks Lawrence to arrange the cupcakes in the ascending order of their values. Now he gives him Q queries to answer. In each query Kone gives three integers L,R,K where L,R are indices of the array. Lawrence needs to print the number of subarrays in the subarray A[L…R] which have K distinct elements. Constraints: - 1?Ai??100 - 1?N?5?104 - 1?Q?50 - 0?L?R?N?1 - 1?K?N Input The first line contains two spaced integers N and Q. The next line contains N spaces integers Ai? denoting the values of the cupcakes. Each of the next Q lines contain 3 integers L,R,K. Output Print the number of subarrays in the subarray A[L…R] which have K distinct elements for every query in separate line.
Examples \begin{tabular}{|l|l|} \hline input & Copy \\ \hline 72 \\ 6066945659867 \\ 457 \\ 566 \\ \hline output & Copy \\ \hline 0 \\ 0 & \\ \hline \end{tabular}