The present invention relates to pyrazolopyrimidinone or pyrrolotriazinone derivatives, the preparation method and medical use thereof. Specifically, the present invention relates to a novel pyrazolopyrimidinone or pyrrolotriazinone derivative represented by formula (I), the preparation methods thereof, the pharmaceutical composition containing the same, the use of the same as a gonadotropin-releasing hormone (GnRH) receptor antagonist, especially the uses for treatment of endometriosis disease, wherein each substituent of formula (I) is as defined in the specification.本發明涉及吡唑並嘧啶酮類或吡咯並三嗪酮類衍生物、其製備方法及其在醫藥上的應用。具體而言,本發明涉及一種通式(I)所示的吡唑並嘧啶酮類或吡咯並三嗪酮類衍生物及其可藥用的鹽,其製備方法以及它們作為促性腺素釋放激素(GnRH)受體拮抗劑特別是作為子宮內膜異位症等治療劑的用途,其中通式(I)中的各取代基的定義與說明書中的定義相同。□