結果

問題 No.1024 Children in a Row
ユーザー chocoruskchocorusk
提出日時 2020-04-08 12:49:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,546 bytes
コンパイル時間 419 ms
コンパイル使用メモリ 11,112 KB
実行使用メモリ 123,384 KB
最終ジャッジ日時 2023-10-12 07:42:03
合計ジャッジ時間 14,496 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 19 ms
8,768 KB
testcase_01 AC 18 ms
8,720 KB
testcase_02 AC 19 ms
8,924 KB
testcase_03 AC 24 ms
8,932 KB
testcase_04 AC 22 ms
9,016 KB
testcase_05 AC 23 ms
8,996 KB
testcase_06 AC 25 ms
9,068 KB
testcase_07 AC 23 ms
8,908 KB
testcase_08 AC 23 ms
8,948 KB
testcase_09 AC 24 ms
8,860 KB
testcase_10 TLE -
testcase_11 TLE -
testcase_12 TLE -
testcase_13 TLE -
testcase_14 TLE -
testcase_15 TLE -
testcase_16 TLE -
testcase_17 TLE -
testcase_18 TLE -
testcase_19 TLE -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import deque
import bisect
n, m=map(int, input().split())
a=[0]*m
b=[0]*m
k=[0]*m
c=[i for i in range(n)]
cr=[0]*(n+m)
for i in range(n):
    cr[i]=i
g=[[] for i in range(n+m)]
pr=[0]*m
for i in range(m):
    a[i], b[i], k[i]=map(int, input().split())
    a[i]-=1
    b[i]-=1
    g[c[b[i]]].append(i+n)
    pr[i]=c[a[i]]
    c[a[i]]=i+n
    cr[i+n]=a[i]
st=[]
l=[0]*(n+m)
r=[0]*(n+m)
rev=[0]*(n+m)
t=0
for i in range(n):
    st.append(i)
    while len(st)!=0:
        x=st.pop()
        if len(st)==0:
            if i<n-1:
                r[x]=i+1
            else:
                r[x]=n+m
        else:
            r[x]=st[len(st)-1]
        l[x]=t
        rev[t]=x
        t+=1
        for y in g[x]:
            st.append(y)
for i in range(n+m):
    if r[i]<n+m:
        r[i]=l[r[i]]
cnt=[0]*(n+m+1)
cntr=[0]*(n+1)
for i in range(n+m):
    cnt[i+1]=cnt[i]
    if c[cr[rev[i]]]==rev[i]:
        cnt[i+1]+=1
        cntr[cnt[i+1]]=i
for i in range(m):
    l1=l[i+n]
    r1=r[i+n]
    l2=l[pr[i]]
    ans=0
    if l1<l2:
        if k[i]<=cnt[l1] or k[i]>cnt[l2]:
            ans=cr[rev[cntr[k[i]]]]
        elif k[i]<=cnt[l1]+cnt[l2]-cnt[r1]:
            ans=cr[rev[cntr[k[i]-cnt[l1]+cnt[r1]]]]
        else:
            ans=cr[rev[cntr[k[i]-cnt[l2]+cnt[r1]]]]
    else:
        if k[i]<=cnt[l2] or k[i]>cnt[r1]:
            ans=cr[rev[cntr[k[i]]]]
        elif k[i]<=cnt[l2]+cnt[r1]-cnt[l1]:
            ans=cr[rev[cntr[k[i]-cnt[l2]+cnt[l1]]]]
        else:
            ans=cr[rev[cntr[k[i]-cnt[r1]+cnt[l1]]]]
    print(ans+1)
0