Binary Majid


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Majid has a binary string of length nn with only 1 values. One morning, his niece accidentally finds this string and starts destroying it. She destroys the string in tt steps. The niece first chooses a sequence of integers: 1a1a2atn1 \leq a_1 \leq a_2 \leq \dots \leq a_t \leq n. Then, in the ii-th step, she selects the first aia_i bits and destroys this part as follows:

  • First, she negates all the selected bits.
  • Then, she reverses the order of the selected part.

To be more precise, if the binary string before the ii-th step is as follows:

S=s1s2,,snS = s_1 s_2, \dots, s_n

The binary string after the ii-th step will be as follows, where sˉi\bar{s}_i represents the negation of bit sis_i:

S=sˉai,sˉai1,,sˉ1,sai+1,,snS = \bar{s}_{a_i}, \bar{s}_{a_i-1}, \dots, \bar{s}_1, s_{a_i+1}, \dots, s_n

Majid wants to restore the string to its initial state using his superpower. Each time Majid uses his superpower, he chooses two numbers 1lrn1 \leq l \leq r \leq n. Then, magically, all the bits in positions from ll to rr inclusive are negated. This interval includes the bits at positions ll and rr themselves. The positions of the bits are considered from left to right, and the leftmost bit has a position of 11.

Help Majid restore the string to its initial state with the fewest number of uses of his superpower.

ورودی🔗

The first line of the input consists of two integers nn (1n1018)(1 \leq n \leq 10^{18}) and tt (1t105)(1 \leq t \leq 10^5) separated by a space, which is the length of the string and the number of steps of string destruction, respectively.
The second line contains a sequence of integers a1,a2,,ata_1, a_2, \dots, a_t (1ain)(1 \leq a_i \leq n), chosen by the niece.

خروجی🔗

Print kk, the minimum number of times Majid needs to use his superpower in the first line.
Then, in the (i+1)(i+1)th line (1ik)(1 \leq i \leq k) of the output, print the interval that Majid chooses in his use of superpower as two numbers separated by a space, in ascending order.

ورودی نمونه 1🔗

5 2
2 5
Plain text

خروجی نمونه 1🔗

1
1 3
Plain text

ورودی نمونه 2🔗

5 2
3 3
Plain text

خروجی نمونه 2🔗

0
Plain text
ارسال پاسخ برای این سؤال
در حال حاضر شما دسترسی ندارید.