Number of Balloons
Practice
3.4 (10 votes)
Advanced data structures
Data structures
Medium
Segment trees
Problem
89% Success 3212 Attempts 50 Points 2s Time Limit 256MB Memory 1024 KB Max Code

You have arranged balloons in a linear order. Every balloon is colored and the \(i^{th}\) balloon's color is represented by \(C_i\). Here, the color of balloons is depicted with numbers. 

The number \(k\) is not a suitable number, therefore you decide to use it for the less number of times. You do not contain any range of ballons in which a color repeats exactly \(k\) times. If the displayed balloons are numbered from \(b_0, b_1, b_2,...,b_{n-1}\), then the range of balloons from \(l\) to \(r\) is \(b_l, b_{l+1}, b_{l+2},...,b_r\).

You are provided with some specific ranges and your task is to determine the number of colors that get repeated for exactly \(k\) times in each range that is provided.

Input format

  • First line: Three integers \(n\), \(k\), and \(q\) (\(1\le n,\ k,\ q \le 100000\)). Here, \(n\) is the number of balloons, \(k\) is the inappropriate number, and \(q\) is the number of queries.
  • Second line: Contains \(n\) integers depicting the color of balloons (\(1\le ci\le 1000\cdot 1000\cdot 1000\))
  • Each \(q\) lines: Contains two integers \(l\) and \(r\) (\(0\le l,\ r<n\))

Output format

Print the number of colors that are repeated exactly k times. If the answer to the previous query is \(ans\) (answer for the first query is \(0\)), then the range of the answer should be \(min((l+ans) \% n,(r+ans) \%n)\ and\ max((l+ans)\%n,(r+ans)\%n)\).

.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
6 votes
Tags:
Advanced Data StructuresSegment TreesC++Data Structures
Points:50
8 votes
Tags:
MediumSegment Trees
Points:50
8 votes
Tags:
Advanced Data StructuresData StructuresSegment Trees