Permutation Minimization by Deque

In fact, the problems E1 and E2 do not have much in common. You should probably think of them as two separate problems.

A permutation pp of size nn is given. A permutation of size nn is an array of size nn in which each integer from 11 to nn occurs exactly once. For example, [1,4,3,2][1,4,3,2] and [4,2,1,3][4,2,1,3] are correct permutations while [1,2,4][1,2,4] and [1,2,2][1,2,2] are not.

Let us consider an empty deque (double-ended queue). A deque is a data structure that supports adding elements to both the beginning and the end. So, if there are elements [1,5,2][1,5,2] currently in the deque, adding an element 44 to the beginning will produce the sequence [4,1,5,2][4,1,5,2], and adding same element to the end will produce [1,5,2,4][1,5,2,4].

The elements of the permutation are sequentially added to the initially empty deque, starting with p1p1 and finishing with pnpn. Before adding eac

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值