DMOPC '22 Contest 5 P3 - Sorted XOR

View as PDF

Submit solution


Points: 12 (partial)
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

Anthony is obsessed with sorting algorithms. After mastering a couple different sorting algorithms, he is now learning how to solve more unconventional sorting problems. Initially, there is an array A of size N. Anthony can perform the following operation any number of times: change an element of A to any arbitrarily large non-negative integer. Let the array B be the prefix bitwise XOR array of A. Formally, Bi=A1A2Ai. Please tell Anthony the minimum number of operations to sort B in non-decreasing order.

Constraints

1N106

0Ai<230

Subtask 1 [20%]

1N103

0Ai<28

Subtask 2 [80%]

No additional constraints.

Input Specification

The first line contains the integer N.

The next line contains N space-separated integers, representing the array A.

Output Specification

Output the minimum number of operations to make B nondecreasing.

Sample Input

Copy
3
2 2 4

Sample Output

Copy
1

Explanation for Sample

1 operation can be performed by changing the first element to 0, making B nondecreasing.


Comments

There are no comments at the moment.