Code for USACO practice problems
cpp
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

33 lines
673 B

#include <cstdio>
#include <iostream>
using namespace std;
int main() {
freopen("bcount.in", "r", stdin);
freopen("bcount.out", "w", stdout);
int n, q;
cin >> n >> q;
int cow_array[n];
for (int i = 0; i < n; i++) {
int j;
cin >> j;
cow_array[i] = j;
}
for (int i = 0; i < q; i++) {
int j, k;
cin >> j >> k;
int a = 0;
int b = 0;
int c = 0;
for (int i = 0; i < abs(j - k) + 1; i++) {
if (cow_array[i + j - 1] == 1) {
a++;
} else if (cow_array[i + j - 1] == 2) {
b++;
} else if (cow_array[i + j - 1] == 3) {
c++;
}
}
cout << a << " " << b << " " << c << endl;
}
}