" (Family name) + title + hǎo" is a common way of greeting people in Mandarin. This form of greeting is used only when addressing teachers, elders, or individuals of higher authority.
The question "请问您贵姓?" is a polite way to inquire about someone's surname. In Mandarin, people use "您" as a polite form of address. If you want to address seniors and show respect, you can use "nín 您" (you, singular and polite form) instead of "nǐ 你" (you, singular) in Mandarin. It is important to know that "您" does not have a plural form and can be used to refer to both a single person and couples of people, so in Mandarin, people do not say “*nínmen 您们”. Note that in Cantonese, "您" and "你" are both pronounced as "nei5" (you).