Hi!
On the question “Breed Counting” (USACO Silver December 2015), I’m getting an error on the sample case, but the output and correct answer is the same. Can someone please help me figure out what I’ve done wrong in my code? It’s in C++ - thanks!
#include <bits/stdc++.h>
using namespace std;
int n, q;
vector<int> h;
vector<int> g;
vector<int> j;
int main(){
int a;
ifstream fin("bcount.in");
ofstream fout("bcount.out");
h.push_back(0);
g.push_back(0);
j.push_back(0);
int b;
int ctrh = 0, ctrg = 0, ctrj = 0;
fin >> n >> q;
for(int i = 1; i < n+1; i++){
fin >> a;
if(a == 1){
ctrh ++;
}
h[i] = ctrh;
if(a == 2){
ctrg ++;
}
g[i] = ctrg;
if(a == 3){
ctrj ++;
}
j[i] = ctrj;
}
int h1, g1, j1;
for(int i = 0; i < q; i++){
fin >> a >> b;
h1 = h[b] - h[a-1];
fout << h1;
fout << " ";
g1 = g[b] - g[a-1];
fout << g1;
fout << " ";
j1 = j[b] - j[a-1];
fout << j1;
fout << "\n";
}
fout.close();
}