結果

問題 No.2002 Range Swap Query
ユーザー vwxyzvwxyz
提出日時 2023-03-30 18:10:58
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 1,309 bytes
コンパイル時間 109 ms
コンパイル使用メモリ 12,156 KB
実行使用メモリ 12,828 KB
最終ジャッジ日時 2023-10-22 03:29:06
合計ジャッジ時間 7,446 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
10,320 KB
testcase_01 AC 29 ms
10,384 KB
testcase_02 AC 27 ms
10,292 KB
testcase_03 AC 25 ms
10,260 KB
testcase_04 AC 24 ms
10,320 KB
testcase_05 AC 26 ms
10,260 KB
testcase_06 AC 26 ms
10,384 KB
testcase_07 AC 26 ms
10,384 KB
testcase_08 AC 111 ms
11,536 KB
testcase_09 AC 55 ms
12,828 KB
testcase_10 AC 29 ms
10,392 KB
testcase_11 AC 97 ms
11,848 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline=sys.stdin.readline

def Mo(N,Q,query):
    D=max(1,int(N/Q**.5))
    mo=[[] for d in range((N+D-1)//D+1)]
    for q,(l,r) in enumerate(query):
        mo[l//D].append(q)
    retu=[]
    for d in range((N+D-1)//D+1):
        retu+=sorted(mo[d],reverse=d%2,key=lambda q:query[q][1])
    return retu

N,K,Q=map(int,readline().split())
A,B=[],[]
for k in range(K):
    a,b=map(int,readline().split())
    a-=1;b-=1
    A.append(a)
    B.append(b)
query=[]
for q in range(Q):
    l,r,x=map(int,readline().split())
    l-=1
    x-=1
    query.append((l,r,x))
ans_lst=[None]*Q
L,R=0,0
perm=[i for i in range(N)]
idx=[i for i in range(N)]
for q in Mo(K,Q,[(l,r) for l,r,x in query]):
    l,r,x=query[q]
    while l<L:
        L-=1
        idx[A[L]],idx[B[L]]=idx[B[L]],idx[A[L]]
        perm[idx[A[L]]]=A[L]
        perm[idx[B[L]]]=B[L]
    while R<r:
        perm[A[R]],perm[B[R]]=perm[B[R]],perm[A[R]]
        idx[perm[A[R]]]=A[R]
        idx[perm[B[R]]]=B[R]
        R+=1
    while L<l:
        idx[A[L]],idx[B[L]]=idx[B[L]],idx[A[L]]
        perm[idx[A[L]]]=A[L]
        perm[idx[B[L]]]=B[L]
        L+=1
    while r<R:
        R-=1
        perm[A[R]],perm[B[R]]=perm[B[R]],perm[A[R]]
        idx[perm[A[R]]]=A[R]
        idx[perm[B[R]]]=B[R]
    ans_lst[q]=perm[x]+1
print(*ans_lst,sep="\n")
0