add aloha/2025cherry set

This commit is contained in:
2025-05-17 17:25:42 +09:00
parent 8158c38e23
commit bac11c76e0
4 changed files with 137 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
import sys
input = sys.stdin.readline
class ReverseSortTracer:
def __init__(self, n, arr):
self.n = n
self.arr = arr
def sort_trace(self) -> list[tuple[int, int]]:
qx = []
sorted_arr = self.arr.copy()
for i in range(1, self.n):
l = i
r = sorted_arr.index(i) + 1
for ptr in range((r - l + 1) // 2):
sorted_arr[l + ptr - 1], sorted_arr[r - 1 - ptr] = \
sorted_arr[r - 1 - ptr], sorted_arr[l + ptr - 1]
qx.append((l, r))
return qx
if __name__ == "__main__":
n = int(input())
arr = list(map(int, input().split()))
solved = ReverseSortTracer(n, arr).sort_trace()
print(len(solved))
for pair in solved:
print(*pair)