Submission #52699722


Source Code Expand

Copy
import array
modBase = 998244353
n, q = map(int, input().split())
par = array.array("l", [-1 for _ in range (n+1)])
def redirect(x,y):
while x >= 0:
par[x], y, x = y, x, par[x]
x1 = 1
for _ in range(q):
a, b, c = map(int, input().split())
t = (a * x1 % modBase) % 2 + 1
u = (b * x1 % modBase) % n + 1
v = (c * x1 % modBase) % n + 1
if t == 1:
x = u
y = v
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
import array

modBase = 998244353

n, q = map(int, input().split())

par = array.array("l", [-1 for _ in range (n+1)])

def redirect(x,y):
    while x >= 0:
        par[x], y, x = y, x, par[x]

x1 = 1
for _ in range(q):
    a, b, c = map(int, input().split())
    t = (a * x1 % modBase) % 2 + 1
    u = (b * x1 % modBase) % n + 1
    v = (c * x1 % modBase) % n + 1
    if t == 1:
        x = u
        y = v
        while (x >= 0 and y >= 0):
            x = par[x]
            y = par[y]
        if x == -1:
            redirect(u,v)
        else:
            redirect(v,u)
    else:
        pb = par[u]
        pc = par[v]
        ppb = -1 if pb == -1 else par[pb]
        ppc = -1 if pc == -1 else par[pc]
        x1 = pb if ppb == v else pc if ppc == u else pb if pb == pc and pb != -1 else 0
        print(x1)
        x1 = x1 + 1

# オレ流マージテクで
# 実績あるアルゴリズムをPythonでも。

Submission Info

Submission Time
Task G - Mediator
User joetheshootingst
Language Python (PyPy 3.10-v7.3.12)
Score 600
Code Size 956 Byte
Status AC
Exec Time 340 ms
Memory 88912 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 600 / 600
Status
AC × 2
AC × 87
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All sample_01.txt, sample_02.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt, test_31.txt, test_32.txt, test_33.txt, test_34.txt, test_35.txt, test_36.txt, test_37.txt, test_38.txt, test_39.txt, test_40.txt, test_41.txt, test_42.txt, test_43.txt, test_44.txt, test_45.txt, test_46.txt, test_47.txt, test_48.txt, test_49.txt, test_50.txt, test_51.txt, test_52.txt, test_53.txt, test_54.txt, test_55.txt, test_56.txt, test_57.txt, test_58.txt, test_59.txt, test_60.txt, test_61.txt, test_62.txt, test_63.txt, test_64.txt, test_65.txt, test_66.txt, test_67.txt, test_68.txt, test_69.txt, test_70.txt, test_71.txt, test_72.txt, test_73.txt, test_74.txt, test_75.txt, test_76.txt, test_77.txt, test_78.txt, test_79.txt, test_80.txt, test_81.txt, test_82.txt, test_83.txt, test_84.txt, test_85.txt
Case Name Status Exec Time Memory
sample_01.txt AC 59 ms 76616 KB
sample_02.txt AC 58 ms 76624 KB
test_01.txt AC 58 ms 76604 KB
test_02.txt AC 57 ms 76568 KB
test_03.txt AC 58 ms 76780 KB
test_04.txt AC 340 ms 86588 KB
test_05.txt AC 161 ms 86244 KB
test_06.txt AC 308 ms 86564 KB
test_07.txt AC 257 ms 88896 KB
test_08.txt AC 308 ms 84844 KB
test_09.txt AC 300 ms 88288 KB
test_10.txt AC 227 ms 87848 KB
test_11.txt AC 309 ms 86876 KB
test_12.txt AC 304 ms 86036 KB
test_13.txt AC 253 ms 87100 KB
test_14.txt AC 319 ms 88372 KB
test_15.txt AC 165 ms 86052 KB
test_16.txt AC 323 ms 87540 KB
test_17.txt AC 320 ms 87468 KB
test_18.txt AC 328 ms 85496 KB
test_19.txt AC 326 ms 86892 KB
test_20.txt AC 325 ms 88188 KB
test_21.txt AC 308 ms 87088 KB
test_22.txt AC 325 ms 86712 KB
test_23.txt AC 235 ms 88912 KB
test_24.txt AC 228 ms 85332 KB
test_25.txt AC 212 ms 86052 KB
test_26.txt AC 197 ms 84584 KB
test_27.txt AC 218 ms 85892 KB
test_28.txt AC 321 ms 86464 KB
test_29.txt AC 254 ms 87284 KB
test_30.txt AC 247 ms 87612 KB
test_31.txt AC 265 ms 87164 KB
test_32.txt AC 206 ms 84584 KB
test_33.txt AC 238 ms 85292 KB
test_34.txt AC 202 ms 87288 KB
test_35.txt AC 210 ms 85248 KB
test_36.txt AC 227 ms 85132 KB
test_37.txt AC 243 ms 85024 KB
test_38.txt AC 304 ms 88004 KB
test_39.txt AC 311 ms 86064 KB
test_40.txt AC 174 ms 85852 KB
test_41.txt AC 217 ms 86564 KB
test_42.txt AC 184 ms 85908 KB
test_43.txt AC 261 ms 88208 KB
test_44.txt AC 182 ms 85244 KB
test_45.txt AC 230 ms 86372 KB
test_46.txt AC 188 ms 85804 KB
test_47.txt AC 242 ms 86180 KB
test_48.txt AC 179 ms 85180 KB
test_49.txt AC 233 ms 87012 KB
test_50.txt AC 183 ms 85284 KB
test_51.txt AC 231 ms 86672 KB
test_52.txt AC 182 ms 85568 KB
test_53.txt AC 207 ms 86200 KB
test_54.txt AC 175 ms 84704 KB
test_55.txt AC 220 ms 86864 KB
test_56.txt AC 129 ms 85248 KB
test_57.txt AC 128 ms 85060 KB
test_58.txt AC 127 ms 84908 KB
test_59.txt AC 128 ms 84972 KB
test_60.txt AC 190 ms 84608 KB
test_61.txt AC 187 ms 84880 KB
test_62.txt AC 167 ms 85644 KB
test_63.txt AC 165 ms 85436 KB
test_64.txt AC 216 ms 85072 KB
test_65.txt AC 227 ms 86528 KB
test_66.txt AC 230 ms 87828 KB
test_67.txt AC 183 ms 84608 KB
test_68.txt AC 189 ms 84972 KB
test_69.txt AC 189 ms 84868 KB
test_70.txt AC 193 ms 85248 KB
test_71.txt AC 194 ms 85140 KB
test_72.txt AC 189 ms 84356 KB
test_73.txt AC 188 ms 84820 KB
test_74.txt AC 163 ms 85428 KB
test_75.txt AC 168 ms 84884 KB
test_76.txt AC 271 ms 86364 KB
test_77.txt AC 277 ms 86468 KB
test_78.txt AC 258 ms 85540 KB
test_79.txt AC 245 ms 85352 KB
test_80.txt AC 285 ms 85596 KB
test_81.txt AC 267 ms 85964 KB
test_82.txt AC 267 ms 85640 KB
test_83.txt AC 263 ms 85496 KB
test_84.txt AC 248 ms 85396 KB
test_85.txt AC 281 ms 85964 KB


2025-04-26 (Sat)
02:55:43 +00:00