Company: Infosys SP
Difficulty: medium
Sum of Indices for Good Subarrays Given an array a of length n ( 1 ≤ n ≤ 10 5 ), where 1 ≤ a[i] ≤ 10 5 , and a positive integer k ( 1 ≤ k ≤ 10 5 ). We call the subarray from l to r good , if for each element that appears in the subarray from l to r , the number of its occurrences in this subarray is equal to k . You have to process q queries ( 1 ≤ q ≤ 10 5 ), each query contains two integers l and r . For each of these queries, find if the subarray from l to r is good. Print the sum of indices of queries that have a \"Yes\" answer, modulo 10 9 + 7 . Input Format The first line contains an integer n , denoting the number of elements in a . The next line contains an integer k , denoting the number that describes a good subarray. Each of the n subsequent lines contains an integer describing a[i] . The next line contains an integer q , denoting the number of rows in queries. The next line contains an integer two , denoting the number of columns in queries. Each of the q subsequent lines co