Submission #51078968


Source Code Expand

from collections import defaultdict

n=int(input())
a=list(map(int,input().split()))

q=int(input())

next_num=defaultdict(int)
pre_num =defaultdict(int)

for i in range(n):
  if i==0:
    pre_num[a[i]] = 0
    next_num[0] = a[i]
  else:
    pre_num[a[i]] = a[i-1]
  
  if i==n-1:
    next_num[a[i]]= 0
    pre_num[0] = a[i]
  else:
    next_num[a[i]]=a[i+1]
  
for _ in range(q):
  query=list(map(int,input().split()))
  if query[0]==1:
    x,y=query[1],query[2]
    
    nx = next_num[x]
    next_num[x] = y
    
    pre_num[y] = x
    next_num[y] = nx
    
    pre_num[nx] = y
  else:
    x=query[1]
    px = pre_num[x]
    nx = next_num[x]
    
    next_num[px] = nx
    pre_num[nx] = px
    
ans = []
nx = 0

while True:
  nx = next_num[nx]
  if nx == 0:
    break
  ans.append(nx)

print(*ans)

Submission Info

Submission Time
Task E - Insert or Erase
User gootara
Language Python (PyPy 3.10-v7.3.12)
Score 475
Code Size 851 Byte
Status AC
Exec Time 688 ms
Memory 239220 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 475 / 475
Status
AC × 2
AC × 24
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
min.txt AC 73 ms 76824 KiB
random_01.txt AC 688 ms 239220 KiB
random_02.txt AC 527 ms 179088 KiB
random_03.txt AC 464 ms 192552 KiB
random_04.txt AC 260 ms 115472 KiB
random_05.txt AC 576 ms 187156 KiB
random_06.txt AC 452 ms 143156 KiB
random_07.txt AC 500 ms 187616 KiB
random_08.txt AC 263 ms 124964 KiB
random_09.txt AC 438 ms 187496 KiB
random_10.txt AC 300 ms 121256 KiB
random_11.txt AC 400 ms 187128 KiB
random_12.txt AC 144 ms 91692 KiB
random_13.txt AC 477 ms 233136 KiB
random_14.txt AC 377 ms 187464 KiB
random_15.txt AC 338 ms 187056 KiB
random_16.txt AC 484 ms 233744 KiB
random_17.txt AC 379 ms 187144 KiB
random_18.txt AC 340 ms 187620 KiB
random_19.txt AC 242 ms 136280 KiB
random_20.txt AC 345 ms 231532 KiB
random_21.txt AC 226 ms 178996 KiB
sample_01.txt AC 74 ms 77104 KiB
sample_02.txt AC 75 ms 76816 KiB