ඖͷ͏͗͞ ʙ/ ͕͍·͢ɻ͜ΕΒ ඖͷ͏͕͗͞ెڝΛ͠·ͨ͠ɻ ಉண͍·ͤΜͰͨ͠ɻߴڮ܅ ਓͷ؍٬͔ΒใΛूΊ·ͨ͠ɻ ൪ͷ؍٬ʹΑΔͱɺ͏͗͞ ͏͗͞ ΑΓઌʹΰʔϧͨͦ͠͏Ͱ͢ɻ ͯ͢ͷ؍٬ͷใʹ߹க͢ΔΑ͏ͳணॱ͕Կ௨Γߟ͑ΒΕΔ͔ٻΊ͍ͯͩ͘͞ɻ ͷͯ͢૬ҟͳΔɻ ͯ͢ͷ؍٬ͷใʹ߹க͢ΔΑ͏ͳணॱ͕গͳ͘ͱͻͱͭଘࡏ͢Δɻ N N M i xi yi 2 ≤ N ≤ 16 1 ≤ M ≤ N(N − 1)/2 1 ≤ xi , yi ≤ N xi ≠ yi (xi , yi ) "U$PEFS#FHJOOFS$POUFTU%ెڝIUUQTBUDPEFSKQDPOUFTUTBCDUBTLTBCD@E ྫ N = 4 M = 3 w ΑΓઌʹΰʔϧ w ΑΓઌʹΰʔϧ w ΑΓઌʹΰʔϧ ύλʔϯaணॱ Ґ Ґ Ґ Ґ ͏͗͞ શ෦Ͱ௨Γ
ʹ͍ͭͯɺࡼJʹ ݸͷण͕࢘ஔ͔Ε͍ͯ·͢ɻ ͯ͢ͷण͕࢘ແ͘ͳΔ·Ͱɺଠ܅࣍ͷૢ࡞Λ܁Γฦ͠ߦ͍·͢ɻ ͷ͕֬Ͱग़ΔαΠίϩΛৼΓɺग़Λͱ͢Δɻ ࡼʹण͕࢘͋Δ߹ɺࡼͷण࢘Λݸ৯Δɻࡼʹण͕࢘ແ͍߹ɺԿߦΘͳ͍ɻ ͯ͢ͷण͕࢘ແ͘ͳΔ·Ͱͷૢ࡞ճͷظΛٻΊ͍ͯͩ͘͞ɻ ೖྗͯ͢Ͱ͋Δɻ 1,2,…, N i (1 ≤ i ≤ N) ai (1 ≤ ai ≤ 3) 1,2,…, N i i i i 1 ≤ N ≤ 300 1 ≤ ai ≤ 3 IUUQTBUDPEFSKQDPOUFTUTEQTVCNJTTJPOT EQ<J><K><L> ͷࡼ ͷࡼ ͷࡼʹ͓͚Δૢ࡞ճͷظ ai = 1 i ai = 2 j ai = 3 k w ํͱղྫ EPVCMFEGT MMJ MMK MML \ JG EQ<J><K><L> SFUVSOEQ<J><K><L> JG JKL SFUVSO EPVCMFJKL EPVCMF J K LEPVCMFSFTOJKL JG L SFT EGT J K L EPVCMF LJKL JG K SFT EGT J K L EPVCMF KJKL JG J SFT EGT J K L EPVCMF JJKL SFUVSOEQ<J><K><L>SFT ^ w શࡼ֬ͰબΕΔͷͰɺ ͷॱ൪ Өڹ͠ͳ͍ w ঢ়ଶͱͯ͠ࡼ͝ͱͷૢ࡞ճͷظ Λߟ͑Δ ai
ͷݩΛͻͱͭબͼɺࢁ͔Βͪΐ͏ͲݸͷੴΛऔΓڈΔɻ ઌʹૢ࡞Λߦ͑ͳ͘ͳͬͨਓ͕ෛ͚Ͱ͢ɻ ೋਓ͕࠷దʹߦಈ͢ΔͱԾఆͨ͠ͱ͖ɺͲͪΒ͕উ͔ͭΛఆ͍ͯͩ͘͠͞ɻ ೖྗͯ͢Ͱ͋Δɻ N A = a1 , a2 , …, aN K A x x 1 ≤ N ≤ 102 1 ≤ K ≤ 105 1 ≤ a1 < a2 < ⋯ < aN ≤ K &EVDBUJPOBM%1$POUFTU%1·ͱΊίϯςετ,4UPOFTIUUQTBUDPEFSKQDPOUFTUTEQUBTLTEQ@L IUUQTBUDPEFSKQDPOUFTUTEQTVCNJTTJPOT EQ<J>Γͷੴ͕Jݸʹ͓͚Δ ଠͷউͪঢ়ଶϑϥά w ํͱղྫ w ,ͷ࣌ʜෛ͚ঢ়ଶ ଠͷෛ͚ w ,Jͷ࣌ʜ,dJͰෛ͚ঢ়ଶ͕ ͋ΔͳΒ ෛ͚Λ૬खʹԡ͚͠Δ w ࠨӈͷ۠ؒͷঢ়ଶΛཧ͢Δ%1 ྫEQ<-FGU><3JHIU>۠ؒ<-FGU 3JHIU ͷղ GPS JJL J \GPS KKOK \ B<K>ݸͷੴΛऔΕΔͳΒ औΔ EQ<J>USVF͕ͭͰ͋Ε USVF JG JB<K> \ EQ<J>cEQ<JB<K>> ^ ^^
ݸҰྻʹฒ ΜͰ͍·͢ɻ ࠨ͔Β ݸͷϘʔϧʹॻ͍ͯ͋Δ Ͱɺ৭ Ͱද͞Ε·͢ɻ ͷͱ͖Ϙʔϧ͕ന͍͜ͱΛɺ ͷͱ͖Ϙʔϧ͕ࠇ͍͜ͱΛද͠·͢ɻ ਓؒͷߴڮ܅࣍ͷΑ͏ͳඪΛୡ͍ͨ͠Ͱ͢ɻ Λຬͨ͢ҙͷͷ ʹରͯ͠ɺ͕ॻ͔Εͨന͍Ϙʔϧͷํ͕͕ॻ͔Εͨ ന͍ϘʔϧΑΓࠨʹ͋Δ Λຬͨ͢ҙͷͷ ʹରͯ͠ɺ͕ॻ͔Εͨࠇ͍Ϙʔϧͷํ͕͕ॻ͔Εͨ ࠇ͍ϘʔϧΑΓࠨʹ͋Δ ඪΛୡ͢ΔͨΊʹߴڮ܅࣍ͷΑ͏ͳૢ࡞͕Ͱ͖·͢ɻ ྡΓ߹͏ೋͭͷϘʔϧΛεϫοϓ͢ΔඪΛୡ͢ΔͨΊʹඞཁͳૢ࡞ճͷ࠷খΛٻΊͯͩ͘ ͍͞ɻ ·ͨ ͳΒ 1 N 1 2N i (1 ≤ i ≤ 2N) ai ci ci = W ci = B 1 ≤ i < j ≤ N (i, j) i j 1 ≤ i < j ≤ N (i, j) i j 1 ≤ N ≤ 2000 1 ≤ ai ≤ N ci = W ci = B i ≠ j (ai , ci ) ≠ (aj , cj )
ݸͷΛબͿํ๏ʯͷΛٻΊͯԼ͍͞ɻͨͩ͠ɺಉ͡छྨͷ۠ ผ͠ͳ͍͜ͱͱ͠·͢ɻ ͍ɺ͜Εগ͠؆୯ա͗ΔͷͰɺͪΐͬͱͨ͠จՃ͠Α͏ɻ ͔ΒͳΔ ݸͷ จΛ༻ҙͨ͠ͷͰɺͦΕͧΕʹ͍ͭͯʮ छྨͷΛͪΐ͏Ͳ ݸબͳ͚ΕͳΒͳ͍ͱ ͖ɺ߹ܭ ݸͷΛબͿํ๏ʯͷΛٻΊͯԼ͍͞ɻ N M k, x Q ki xi M 1 ≦ N ≦ 2000 1 ≦ M ≦ 2000 1 ≦ Q ≦ 500,000 1 ≦ ai ≦ M 1 ≦ ki ≦ N 1 ≦ xi ≦ aki EQ<J><K>J൪·ͰͰKݸͷΛબͿ௨Γ EQ<J><K>/छྨͷબͼํ͔Βͭר͖͢༻ͷྻ w ํͱղྫ w ॏෳ߹ͤΛٻΊΔ w ͷݟ͍ͯ͘ॱ൪Θͳ͍ ʹணͯ͠ ࣜมܗ w มܗʹΑΓʮ/छྨͷΛબ Ϳબͼํ͔Βͭר͖͢ʯ͜ ͱ͕Ͱ͖Δ LNKQTCMPHπόαͷඋ DUZMTQSPCMFNTPMWJOHNBZPLP`TEJBSZ w Լهࢀর
6OJPOpOEͰ࿈݁͢Δ 5ZQJDBM%1$POUFTU4ϚεIUUQTUEQDDPOUFTUBUDPEFSKQUBTLTUEQD@HSJE ͢͵͚܅ɺ ͷϚεΛനͱࠇʹృΓ͚Δ͜ͱʹͨ͠ɻ ࠨ্ͷϚεͱӈԼͷϚεࠇʹృΔɻ ࠨ্ͷϚε͔Βɺࠇ͍ϚεΛ্ԼࠨӈʹͨͲͬͯɺӈԼͷϚεʹߦ͘͜ͱ͕Ͱ͖Δɻ ݅Λຬͨ͢ృΓ͚ํͷݸΛNPE ͰٻΊΑɻ H × W 2 ≤ H ≤ 6 2 ≤ W ≤ 100 EQ<J><K>Jྻ·Ͱݟͨ࣌ɼJྻͷ֤ Ϛεͷ࿈͕݁ؔKͰ͋ΔΑ͏ͳృΓํ w ํͱղྫ w ͦΕͧΕͷϚεͷ࿈݁ؔΛͪͳ͕ Β ྻΛࠨ͔Βӈʹݟ͍ͯ͘%1Λߟ͑ Δ w ਐCJU ͰҎԼͷΑ͏ʹߟ͑Δ ന ࠇ͔ͭ ͱ࿈݁ dࠇ͔ͭ ͱ࿈݁Ͱͳ͍ɽ ಉ͡൪߸͕ৼΒΕ͍ͯΕɼͦΕΒͷ Ϛε࿈݁Ͱ͋Δͱߟ͑Δɽ = 7H ͍͢όΧࢽLNKQTCMPHTJNF[J@UBOͷه GPS JOUJJX J GPS JOUKKQX<I> K \࣍ঢ়ଶ JG DVS<K> DPOUJOVF GPS JOULL I L \ VOJPO@pOEVG I WFDUPSJOUQ I VG࿈݁ؔΛٻΊΔ GPS JOUMMI M \Q࣍ঢ়ଶͷ֤ߦͷ࿈݁ؔΛอଘ JG LM \࣍ঢ়ଶͷMߦ͕ࠇ JG KQX<M> Q<M>ݱঢ়ଶ͕࿈݁ͳΒ࣍࿈݁ GPS JOUNM NI N \࿈݁ؔΛVGͰ·ͱΊΔ JG LN \ JG NM VGVOJUF M N MͱM ߦ͕ࠇͳΒ࿈݁ FMTF\ JOUVKQX<M> ݱঢ়ଶͷMߦ Nߦͷ࿈݁ؔ WKQX<N> JG VVW VGVOJUF M N ݱঢ়ଶͰಉ͡࿈݁ؔ ^ʜͳΒ࣍ঢ়ଶͰ࿈݁
:PVBSFHJWFOBOBSSBZ"PG/JOUFHFST 5IFDPTUPGBTVCBSSBZJTEFpOFEBTUIFCJUXJTFPSWBMVFPGBMMJUTFMFNFOUT 4VQQPTFZPVTQMJUUIFBSSBZJOUP,,OPOFNQUZTVCBSSBZTBOEZPVDPNQVUFUIFTVNPG UIFJSDPTUT 8IBUJTUIFNBYJNVNWBMVFZPVDBOHFU 1≤K≤N≤2∗10^5 , 0 \leq A_i < 2^{20} IUUQTDTBDBEFNZDPNTVCNJTTJPO ʮG K EQ<J><K>ʯͱͨ͠ͱ͖ʹʮG K G K 㱡G K G K ʯΛຬ͍ͨͯ͠ΕɺܭࢉྔΛམͱ͢ ͜ͱ͕Ͱ͖Δ lԿ͔Λ,ճͬͯίετΛ࠷খԽ͍ͯͩ͘͠͞ɼͰɼEQ<QPT><ͬͨճ>ͩͱ͗͢Δͱ͖ʹɼ ,ճ͏ΘΓʹճ͏ͱYԁേۚɼʹ͢ΕEQ<QPT>ʹग़དྷΔ ͜ͱ͋Δ ςΫ YͰೋ୳ࡧ z CZ!ZPTVQPU ·Μ·Μ·Μɹ$PEFGPSDFTղઆ w Լهࢀর w ίʔυ