The expression a[1] = p3
invokes the assignment operator of shared_ptr. This assignment operator will first decrement the reference counter of the object currently referenced and than increment the reference counter of the object newly referenced.
The reference counter is usually stored along with the reference object, not with the referencing smart pointer.