Your runtime error is because you are attempting to access v[i] prior to initializing any elements in the vector. I would recommend you pass in the number of elements q into the constructor to initialize the vector with q elements of pair<pair<int,int>,int>
to their default state.
int p,q;
cin>> p >> q;
vector<pair<pair<int,int>,int>> v(q);
int i=0;
while(q--)
{
cin>>v[i].first.first>>v[i].first.second>>v[i].second;
i++;
}
I would also recomend looking at Choice between vector::resize() and vector::reserve() which explains 2 other ways to initialize a vector - (resize / reserve).
In short, resizing is similar to that of the constructor mentioned in the code above, except it can be called anytime after construction to suddenly change entire vector length.
Reserve on the other hand does not actually change the vector's length, but changes the vector's underlying capacity (max number of elements that can be stored in the vector prior to the vector having to change it's underlying size). Once a vector has been reserved, push_back() is a very useful function to effectively grow the vector by 1 without increasing the capacity (assuming that initial reserved capacity was large enough).
So for the code above, you could also write it like this:
int p,q;
cin>> p >> q;
vector<pair<pair<int,int>,int>> v;
v.reserve(q) ///reserve large enough here, max capacity here is just q elements
int i=0;
pair<pair<int,int>,int> input;
while(q--)
{
cin>>input.first.first>>input.first.second>>input.second;
v.push_back(input);
i++;
}
In code above your vector's underlying capacity will be q elements, and after while loop finishes it will have a length of q elements as well. The next push_back() operation will be an expensive operation.