实现代码:
n, m = map(int, input().split())
work = []
num = [i for i in range(1, n + 1)]
for i in range(m):
work.append(list(map(int, input().split())))
for i in range(m):
p = work[i][0]
q = work[i][1]
if p == 0 and (q in num):
num1 = num[:q]
num1.sort(reverse=True)
num = num1 + num[q:]
elif p == 1 and (q in num):
num2 = num[q - 1:]
num2.sort()
num = num[:q-1] + num2
while num:
print(num.pop(0), end=" ")
输出效果:
3 3
0 3
1 2
0 2
3 1 2