instead of

Code:
x[i].push_back(r);
try
Code:
x.at(i).push_back(r);
that way you will get bounds checking where [] doesn't check bounds.