Bzoj4397 [usaco 2015 Dec] Breed Counting

Source: Internet
Author: User
Tags cmath

Bzoj4397 [usaco 2015 Dec] Breed Counting

 

4397: [usaco dec] Breed Counting Description

Farmer John's N cows, conveniently numbered 1... N, are all standing in a row (they seem to do so often that it now takes very little prompting from Farmer John to line them up ). each cow has a breed ID: 1 for Holsteins, 2 for Guernseys, and 3 for Jerseys. farmer John wowould like your help counting the number of cows of each breed that lie within certain intervals of the ordering.

 

Given a sequence with a length of N, the number at each position can only be one of 2, 3.

For Q-related queries, each time two numbers a and B are given, please output the numbers 1, 2, and 3 in the range [a, B] respectively.

 

Input

The first line of input contains NN and QQ (1 ≤ N ≤ 100,000 1 ≤ Q ≤ 100,000 ).
The next NN lines contain an integer that is either 1, 2, or 3, giving the breed ID of a single cow in the ordering.
The next QQ lines describe a query in the form of two integers a, B (a ≤ B ).

Output

For each of the QQ queries (a, B), print a line containing three numbers: the number of cows numbered... B that are Holsteins (breed 1), Guernseys (breed 2), and Jerseys (breed 3 ).

Sample Input6 3
2
1
1
3
2
1
1 6
3 3
2 4 Sample Output3 2 1
1 0 0
2 0 1 HINT

 

Source # include # Include
# Include
# Include
# Include
# Include
# Include
# Define F (I, j, n) for (int I = j; I <= n; I ++)
# Define D (I, j, n) for (int I = j; I> = n; I --)
# Define ll long
# Define pa pair
# Define maxn100005
# Define inf 1000000000
Using namespace std;
Int n, m, x, y, sum [4] [maxn];
Inline int read ()
{
Int x = 0, f = 1; char ch = getchar ();
While (ch <'0' | ch> '9') {if (ch = '-') f =-1; ch = getchar ();}
While (ch> = '0' & ch <= '9') {x = x * 10 + ch-'0'; ch = getchar ();}
Return x * f;
}
Int main ()
{
N = read (); m = read ();
F (I, 1, n)
{
F (j, 1, 3) sum [j] [I] = sum [j] [I-1];
X = read ();
Sum [x] [I] ++;
}
F (I, 1, m)
{
X = read (); y = read ();
Printf ("% d \ n", sum [1] [y]-sum [1] [x-1], sum [2] [y]-sum [2] [x-1], sum [3] [y]-sum [3] [x-1]);
}
}
 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.