UOJ Logo 黑暗爆炸OJ

DARKBZOJ

#2984. [Balkan2009]strip

Statistics 下载数据

Description

给一条长为N~10^18的纸带,从左到右每个整数的位置标号为0..N,接下来有K~1W个操作,每次选取位置X,将整条纸带在X处对折。如果X是边缘则什么也不做。问最后纸带长度。

Input

Output

Sample Input

9 5
5 9 2 8 3

Sample Output

2

Hint

The segment names look as follows: 

Starting situation: {0 1 2 3 4 5 6 7 8 9}.

Consecutively applying the folds:


The segment names look as follows: 

Starting situation: {0 1 2 3 4 5 6 7 8 9}.

Consecutively applying the folds:

--> {0 (1;9) (2;8) (3;7) (4;6) 5} --> {(1;9) (0;2;8) (3;7) (4;6) 5} --> {(0;2;8) (1;3;7;9) (4;6) 5} -->

{(0;2;8) (1;3;7;9) (4;6) 5} --> {(1;3;7;9) (0;2;4;6;8) 5}. 

 

 

Source