Company: Cisco_8th june_on campus
Difficulty: medium
Online Occurrences You are given an array a of length n (1-indexed). For a subarray from index l to index r (inclusive), define beauty(l, r) as the maximum integer x such that the value x appears at least x times in the subarray a[l..r] . If no positive integer satisfies this, beauty(l, r) = 0. You are given q queries. Each query provides two integers l and r . The queries are encoded (online) : let S be the sum of the answers to all previous queries (for the first query, S = 0 ). Before answering query i , decode l and r as follows: l = ((l + S - 1) mod n) + 1 r = ((r + S - 1) mod n) + 1 if l > r , then swap l and r . The answer to query i is beauty(l, r) on the decoded indices. Note that S is the running sum of decoded answers and is used (not reduced modulo anything) when decoding subsequent queries. Output a single integer: the sum of the answers to all q queries, taken modulo 10 9 +7 . Input format The first line contains two integers n and q . The second line contains n intege