Breed Counting
InterviewTime limit2sMemory limit512 MB
Given the breed of each cow in a row, report the count of each of the three breeds inside every query interval.
- Level
Easy3 of 10
- Topics
- Prefix sum, Array
- Solved
- No attempts yet
Problem
Farmer John's cows, numbered through , stand in a row. Each cow carries a breed ID: 1 for Holsteins, 2 for Guernseys, and 3 for Jerseys. Given an interval of the row, count how many cows of each breed stand inside it.
Input
The first line contains and (, ).
Each of the next lines contains an integer that is 1, 2, or 3. The number on line is the breed ID of the -th cow in the row.
Each of the next lines contains two integers and describing one query ().
Output
For each query , print three integers on one line, separated by spaces: the number of Holsteins (breed 1), Guernseys (breed 2), and Jerseys (breed 3) among cows through , in that order.